Skip to content

Commit a7997f0

Browse files
committed
typed options
1 parent d7c8a6c commit a7997f0

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

extensions/notebook-renderers/src/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ interface JavaScriptRenderingHook {
2828
preEvaluate(outputItem: OutputItem, element: HTMLElement, script: string, signal: AbortSignal): string | undefined | Promise<string | undefined>;
2929
}
3030

31+
interface RenderOptions {
32+
readonly lineLimit: number;
33+
readonly outputScrolling: boolean;
34+
}
35+
3136
function clearContainer(container: HTMLElement) {
3237
while (container.firstChild) {
3338
container.removeChild(container.firstChild);
@@ -153,7 +158,7 @@ function renderError(outputInfo: OutputItem, container: HTMLElement, ctx: Render
153158
container.classList.add('error');
154159
}
155160

156-
function renderStream(outputInfo: OutputItem, container: HTMLElement, error: boolean, ctx: RendererContext<void> & { readonly settings: { readonly lineLimit: number; readonly outputScrolling: boolean } }): void {
161+
function renderStream(outputInfo: OutputItem, container: HTMLElement, error: boolean, ctx: RendererContext<void> & { readonly settings: RenderOptions }): void {
157162
const outputContainer = container.parentElement;
158163
if (!outputContainer) {
159164
// should never happen
@@ -170,7 +175,7 @@ function renderStream(outputInfo: OutputItem, container: HTMLElement, error: boo
170175
const text = outputInfo.text();
171176

172177
const element = document.createElement('span');
173-
insertOutput(outputInfo.id, [text], ctx.settings.lineLimit, true, element);
178+
insertOutput(outputInfo.id, [text], ctx.settings.lineLimit, ctx.settings.outputScrolling, element);
174179
outputElement.appendChild(element);
175180
return;
176181
}
@@ -180,7 +185,7 @@ function renderStream(outputInfo: OutputItem, container: HTMLElement, error: boo
180185
element.classList.add('output-stream');
181186

182187
const text = outputInfo.text();
183-
insertOutput(outputInfo.id, [text], ctx.settings.lineLimit, true, element);
188+
insertOutput(outputInfo.id, [text], ctx.settings.lineLimit, ctx.settings.outputScrolling, element);
184189
while (container.firstChild) {
185190
container.removeChild(container.firstChild);
186191
}
@@ -205,7 +210,7 @@ export const activate: ActivationFunction<void> = (ctx) => {
205210
const htmlHooks = new Set<HtmlRenderingHook>();
206211
const jsHooks = new Set<JavaScriptRenderingHook>();
207212

208-
const latestContext = ctx as (RendererContext<void> & { readonly settings: { readonly lineLimit: number; readonly outputScrolling: boolean } });
213+
const latestContext = ctx as (RendererContext<void> & { readonly settings: RenderOptions });
209214

210215
const style = document.createElement('style');
211216
style.textContent = `

src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,17 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
241241
private generateContent(coreDependencies: string, baseUrl: string) {
242242
const renderersData = this.getRendererData();
243243
const preloadsData = this.getStaticPreloadsData();
244+
const renderOptions = {
245+
lineLimit: this.configurationService.getValue<number>(NotebookSetting.textOutputLineLimit) ?? 30,
246+
outputScrolling: this.configurationService.getValue<boolean>(NotebookSetting.outputScrolling) ?? true
247+
};
244248
const preloadScript = preloadsScriptStr(
245249
this.options,
246-
{ dragAndDropEnabled: this.options.dragAndDropEnabled }, // add other options
250+
{ dragAndDropEnabled: this.options.dragAndDropEnabled },
251+
renderOptions,
247252
renderersData,
248253
preloadsData,
249254
this.workspaceTrustManagementService.isWorkspaceTrusted(),
250-
this.configurationService.getValue<number>(NotebookSetting.textOutputLineLimit) ?? 30,
251255
this.nonce);
252256

253257
const enableCsp = this.configurationService.getValue('notebook.experimental.enableCsp');

src/vs/workbench/contrib/notebook/browser/view/renderers/webviewPreloads.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,19 @@ export interface PreloadOptions {
6464
dragAndDropEnabled: boolean;
6565
}
6666

67+
export interface RenderOptions {
68+
readonly lineLimit: number;
69+
readonly outputScrolling: boolean;
70+
}
71+
6772
interface PreloadContext {
6873
readonly nonce: string;
6974
readonly style: PreloadStyles;
7075
readonly options: PreloadOptions;
76+
readonly renderOptions: RenderOptions;
7177
readonly rendererData: readonly webviewMessages.RendererMetadata[];
7278
readonly staticPreloadsData: readonly webviewMessages.StaticPreloadMetadata[];
7379
readonly isWorkspaceTrusted: boolean;
74-
readonly lineLimit: number;
7580
}
7681

7782
declare function __import(path: string): Promise<any>;
@@ -82,7 +87,7 @@ async function webviewPreloads(ctx: PreloadContext) {
8287

8388
let currentOptions = ctx.options;
8489
let isWorkspaceTrusted = ctx.isWorkspaceTrusted;
85-
const lineLimit = ctx.lineLimit;
90+
const lineLimit = ctx.renderOptions.lineLimit;
8691

8792
const acquireVsCodeApi = globalThis.acquireVsCodeApi;
8893
const vscode = acquireVsCodeApi();
@@ -2444,14 +2449,14 @@ async function webviewPreloads(ctx: PreloadContext) {
24442449
}();
24452450
}
24462451

2447-
export function preloadsScriptStr(styleValues: PreloadStyles, options: PreloadOptions, renderers: readonly webviewMessages.RendererMetadata[], preloads: readonly webviewMessages.StaticPreloadMetadata[], isWorkspaceTrusted: boolean, lineLimit: number, nonce: string) {
2452+
export function preloadsScriptStr(styleValues: PreloadStyles, options: PreloadOptions, renderOptions: RenderOptions, renderers: readonly webviewMessages.RendererMetadata[], preloads: readonly webviewMessages.StaticPreloadMetadata[], isWorkspaceTrusted: boolean, nonce: string) {
24482453
const ctx: PreloadContext = {
24492454
style: styleValues,
24502455
options,
2456+
renderOptions,
24512457
rendererData: renderers,
24522458
staticPreloadsData: preloads,
24532459
isWorkspaceTrusted,
2454-
lineLimit,
24552460
nonce,
24562461
};
24572462
// TS will try compiling `import()` in webviewPreloads, so use a helper function instead

src/vs/workbench/contrib/notebook/common/notebookCommon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ export const NotebookSetting = {
927927
outputFontSize: 'notebook.outputFontSize',
928928
outputFontFamily: 'notebook.outputFontFamily',
929929
kernelPickerMRU: 'notebook.experimental.kernelPicker.mru',
930-
outputScrolling: 'notebook.outputScrolling',
930+
outputScrolling: 'notebook.expermental.outputScrolling',
931931
} as const;
932932

933933
export const enum CellStatusbarAlignment {

0 commit comments

Comments
 (0)