Skip to content

Commit a64b518

Browse files
Strongly typed instead of any for nb config (microsoft#209493)
* Strongly types instead of `any` for nb config * fix swapped setting fallbacks * Address review comments --------- Co-authored-by: Michael Lively <[email protected]>
1 parent 95885d7 commit a64b518

File tree

5 files changed

+25
-14
lines changed

5 files changed

+25
-14
lines changed

src/vs/workbench/contrib/notebook/browser/contrib/editorStatusBar/editorStatusBar.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,9 @@ export class NotebookIndentationStatus extends Disposable implements IWorkbenchC
305305
}
306306

307307
const cellEditorOverridesRaw = editor.notebookOptions.getDisplayOptions().editorOptionsCustomizations;
308-
const indentSize = cellEditorOverridesRaw['editor.indentSize'] ?? cellOptions?.indentSize;
309-
const insertSpaces = cellEditorOverridesRaw['editor.insertSpaces'] ?? cellOptions?.tabSize;
310-
const tabSize = cellEditorOverridesRaw['editor.tabSize'] ?? cellOptions?.insertSpaces;
308+
const indentSize = cellEditorOverridesRaw?.['editor.indentSize'] ?? cellOptions?.indentSize;
309+
const insertSpaces = cellEditorOverridesRaw?.['editor.insertSpaces'] ?? cellOptions?.insertSpaces;
310+
const tabSize = cellEditorOverridesRaw?.['editor.tabSize'] ?? cellOptions?.tabSize;
311311

312312
const width = typeof indentSize === 'number' ? indentSize : tabSize;
313313

src/vs/workbench/contrib/notebook/browser/notebookOptions.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { PixelRatio } from 'vs/base/browser/pixelRatio';
77
import { CodeWindow } from 'vs/base/browser/window';
88
import { Emitter } from 'vs/base/common/event';
99
import { Disposable } from 'vs/base/common/lifecycle';
10+
import { isObject } from 'vs/base/common/types';
1011
import { URI } from 'vs/base/common/uri';
1112
import { FontMeasurements } from 'vs/editor/browser/config/fontMeasurements';
1213
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
@@ -45,7 +46,11 @@ export interface NotebookDisplayOptions { // TODO @Yoyokrazy rename to a more ge
4546
outputFontFamily: string;
4647
outputLineHeight: number;
4748
markupFontSize: number;
48-
editorOptionsCustomizations: any | undefined;
49+
editorOptionsCustomizations: Partial<{
50+
'editor.indentSize': 'tabSize' | number;
51+
'editor.tabSize': number;
52+
'editor.insertSpaces': boolean;
53+
}> | undefined;
4954
}
5055

5156
export interface NotebookLayoutConfiguration {
@@ -152,7 +157,12 @@ export class NotebookOptions extends Disposable {
152157
// const { bottomToolbarGap, bottomToolbarHeight } = this._computeBottomToolbarDimensions(compactView, insertToolbarPosition, insertToolbarAlignment);
153158
const fontSize = this.configurationService.getValue<number>('editor.fontSize');
154159
const markupFontSize = this.configurationService.getValue<number>(NotebookSetting.markupFontSize);
155-
const editorOptionsCustomizations = this.configurationService.getValue(NotebookSetting.cellEditorOptionsCustomizations);
160+
let editorOptionsCustomizations = this.configurationService.getValue<Partial<{
161+
'editor.indentSize': 'tabSize' | number;
162+
'editor.tabSize': number;
163+
'editor.insertSpaces': boolean;
164+
}>>(NotebookSetting.cellEditorOptionsCustomizations) ?? {};
165+
editorOptionsCustomizations = isObject(editorOptionsCustomizations) ? editorOptionsCustomizations : {};
156166
const interactiveWindowCollapseCodeCells: InteractiveWindowCollapseCodeCells = this.configurationService.getValue(NotebookSetting.interactiveWindowCollapseCodeCells);
157167

158168
// TOOD @rebornix remove after a few iterations of deprecated setting

src/vs/workbench/contrib/notebook/browser/view/cellParts/cellEditorOptions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,15 @@ export class CellEditorOptions extends CellContentPart implements ITextModelUpda
9696

9797
// TODO @Yoyokrazy find a different way to get the editor overrides, this is not the right way
9898
const cellEditorOverridesRaw = this.notebookOptions.getDisplayOptions().editorOptionsCustomizations;
99-
const indentSize = cellEditorOverridesRaw['editor.indentSize'];
99+
const indentSize = cellEditorOverridesRaw?.['editor.indentSize'];
100100
if (indentSize !== undefined) {
101101
this.indentSize = indentSize;
102102
}
103-
const insertSpaces = cellEditorOverridesRaw['editor.insertSpaces'];
103+
const insertSpaces = cellEditorOverridesRaw?.['editor.insertSpaces'];
104104
if (insertSpaces !== undefined) {
105105
this.insertSpaces = insertSpaces;
106106
}
107-
const tabSize = cellEditorOverridesRaw['editor.tabSize'];
107+
const tabSize = cellEditorOverridesRaw?.['editor.tabSize'];
108108
if (tabSize !== undefined) {
109109
this.tabSize = tabSize;
110110
}

src/vs/workbench/contrib/notebook/browser/viewModel/cellEditorOptions.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@ export class BaseCellEditorOptions extends Disposable implements IBaseCellEditor
8383

8484
private _computeEditorOptions() {
8585
const editorOptions = deepClone(this.configurationService.getValue<IEditorOptions>('editor', { overrideIdentifier: this.language }));
86-
const editorOptionsOverrideRaw = this.notebookOptions.getDisplayOptions().editorOptionsCustomizations ?? {};
87-
const editorOptionsOverride: { [key: string]: any } = {};
88-
for (const key in editorOptionsOverrideRaw) {
89-
if (key.indexOf('editor.') === 0) {
90-
editorOptionsOverride[key.substring(7)] = editorOptionsOverrideRaw[key];
86+
const editorOptionsOverrideRaw = this.notebookOptions.getDisplayOptions().editorOptionsCustomizations;
87+
const editorOptionsOverride: Record<string, any> = {};
88+
if (editorOptionsOverrideRaw) {
89+
for (const key in editorOptionsOverrideRaw) {
90+
if (key.indexOf('editor.') === 0) {
91+
editorOptionsOverride[key.substring(7)] = editorOptionsOverrideRaw[key as keyof typeof editorOptionsOverrideRaw];
92+
}
9193
}
9294
}
9395
const computed = Object.freeze({

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,6 @@ export interface INotebookCellStatusBarItemList {
909909
}
910910

911911
export type ShowCellStatusBarType = 'hidden' | 'visible' | 'visibleAfterExecute';
912-
913912
export const NotebookSetting = {
914913
displayOrder: 'notebook.displayOrder',
915914
cellToolbarLocation: 'notebook.cellToolbarLocation',

0 commit comments

Comments
 (0)