Skip to content

Commit 2e33dbc

Browse files
committed
strict null checks (microsoft#60565)
1 parent bb0b08b commit 2e33dbc

27 files changed

Lines changed: 265 additions & 215 deletions

src/tsconfig.strictNullChecks.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"./vs/base/common/idGenerator.ts",
6363
"./vs/base/common/iterator.ts",
6464
"./vs/base/common/jsonSchema.ts",
65+
"./vs/base/common/keybindingLabels.ts",
6566
"./vs/base/common/keybindingParser.ts",
6667
"./vs/base/common/keyCodes.ts",
6768
"./vs/base/common/labels.ts",
@@ -270,10 +271,15 @@
270271
"./vs/editor/contrib/caretOperations/transpose.ts",
271272
"./vs/editor/contrib/clipboard/clipboard.ts",
272273
"./vs/editor/contrib/codeAction/codeActionTrigger.ts",
274+
"./vs/editor/contrib/colorPicker/color.ts",
273275
"./vs/editor/contrib/colorPicker/colorPickerModel.ts",
274276
"./vs/editor/contrib/comment/blockCommentCommand.ts",
277+
"./vs/editor/contrib/comment/comment.ts",
278+
"./vs/editor/contrib/comment/lineCommentCommand.ts",
275279
"./vs/editor/contrib/cursorUndo/cursorUndo.ts",
276280
"./vs/editor/contrib/dnd/dragAndDropCommand.ts",
281+
"./vs/editor/contrib/find/findDecorations.ts",
282+
"./vs/editor/contrib/find/findModel.ts",
277283
"./vs/editor/contrib/find/findState.ts",
278284
"./vs/editor/contrib/find/replaceAllCommand.ts",
279285
"./vs/editor/contrib/find/replacePattern.ts",
@@ -288,12 +294,19 @@
288294
"./vs/editor/contrib/linesOperations/deleteLinesCommand.ts",
289295
"./vs/editor/contrib/linesOperations/sortLinesCommand.ts",
290296
"./vs/editor/contrib/links/getLinks.ts",
297+
"./vs/editor/contrib/links/links.ts",
291298
"./vs/editor/contrib/quickOpen/quickOpen.ts",
292299
"./vs/editor/contrib/toggleTabFocusMode/toggleTabFocusMode.ts",
300+
"./vs/editor/contrib/wordHighlighter/wordHighlighter.ts",
293301
"./vs/editor/contrib/wordOperations/wordOperations.ts",
302+
"./vs/editor/contrib/wordPartOperations/wordPartOperations.ts",
294303
"./vs/editor/editor.worker.ts",
304+
"./vs/editor/standalone/browser/colorizer.ts",
305+
"./vs/editor/standalone/browser/inspectTokens/inspectTokens.ts",
295306
"./vs/editor/standalone/browser/iPadShowKeyboard/iPadShowKeyboard.ts",
296307
"./vs/editor/standalone/browser/standaloneCodeServiceImpl.ts",
308+
"./vs/editor/standalone/browser/standaloneThemeServiceImpl.ts",
309+
"./vs/editor/standalone/browser/toggleHighContrast/toggleHighContrast.ts",
297310
"./vs/editor/standalone/common/monarch/monarchCommon.ts",
298311
"./vs/editor/standalone/common/monarch/monarchCompile.ts",
299312
"./vs/editor/standalone/common/monarch/monarchTypes.ts",
@@ -334,6 +347,7 @@
334347
"./vs/platform/instantiation/common/serviceCollection.ts",
335348
"./vs/platform/integrity/common/integrity.ts",
336349
"./vs/platform/jsonschemas/common/jsonContributionRegistry.ts",
350+
"./vs/platform/keybinding/common/keybinding.ts",
337351
"./vs/platform/keybinding/common/keybindingResolver.ts",
338352
"./vs/platform/keybinding/common/keybindingsRegistry.ts",
339353
"./vs/platform/keybinding/common/resolvedKeybindingItem.ts",

src/vs/base/browser/ui/keybindingLabel/keybindingLabel.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,23 @@ export class KeybindingLabel implements IDisposable {
7171
this.didEverRender = true;
7272
}
7373

74-
private renderPart(parent: HTMLElement, part: ResolvedKeybindingPart, match: PartMatches) {
74+
private renderPart(parent: HTMLElement, part: ResolvedKeybindingPart, match: PartMatches | null) {
7575
const modifierLabels = UILabelProvider.modifierLabels[this.os];
7676
if (part.ctrlKey) {
77-
this.renderKey(parent, modifierLabels.ctrlKey, match && match.ctrlKey, modifierLabels.separator);
77+
this.renderKey(parent, modifierLabels.ctrlKey, Boolean(match && match.ctrlKey), modifierLabels.separator);
7878
}
7979
if (part.shiftKey) {
80-
this.renderKey(parent, modifierLabels.shiftKey, match && match.shiftKey, modifierLabels.separator);
80+
this.renderKey(parent, modifierLabels.shiftKey, Boolean(match && match.shiftKey), modifierLabels.separator);
8181
}
8282
if (part.altKey) {
83-
this.renderKey(parent, modifierLabels.altKey, match && match.altKey, modifierLabels.separator);
83+
this.renderKey(parent, modifierLabels.altKey, Boolean(match && match.altKey), modifierLabels.separator);
8484
}
8585
if (part.metaKey) {
86-
this.renderKey(parent, modifierLabels.metaKey, match && match.metaKey, modifierLabels.separator);
86+
this.renderKey(parent, modifierLabels.metaKey, Boolean(match && match.metaKey), modifierLabels.separator);
8787
}
8888
const keyLabel = part.keyLabel;
8989
if (keyLabel) {
90-
this.renderKey(parent, keyLabel, match && match.keyCode, '');
90+
this.renderKey(parent, keyLabel, Boolean(match && match.keyCode), '');
9191
}
9292
}
9393

@@ -99,7 +99,6 @@ export class KeybindingLabel implements IDisposable {
9999
}
100100

101101
dispose() {
102-
this.keybinding = null;
103102
}
104103

105104
private static areSame(a: Matches, b: Matches): boolean {

src/vs/base/common/keybindingLabels.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ export class ModifierLabelProvider {
2626
public readonly modifierLabels: ModifierLabels[];
2727

2828
constructor(mac: ModifierLabels, windows: ModifierLabels, linux: ModifierLabels = windows) {
29-
this.modifierLabels = [null];
29+
this.modifierLabels = [null!]; // index 0 will never me accessed.
3030
this.modifierLabels[OperatingSystem.Macintosh] = mac;
3131
this.modifierLabels[OperatingSystem.Windows] = windows;
3232
this.modifierLabels[OperatingSystem.Linux] = linux;
3333
}
3434

35-
public toLabel(firstPartMod: Modifiers, firstPartKey: string, chordPartMod: Modifiers, chordPartKey: string, OS: OperatingSystem): string {
35+
public toLabel(firstPartMod: Modifiers, firstPartKey: string, chordPartMod: Modifiers, chordPartKey: string, OS: OperatingSystem): string | null {
3636
if (firstPartKey === null && chordPartKey === null) {
3737
return null;
3838
}

src/vs/editor/browser/editorBrowser.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -803,14 +803,6 @@ export interface IActiveCodeEditor extends ICodeEditor {
803803
*/
804804
getDomNode(): HTMLElement;
805805

806-
/**
807-
* Get the hit test target at coordinates `clientX` and `clientY`.
808-
* The coordinates are relative to the top-left of the viewport.
809-
*
810-
* @returns Hit test target or null if the coordinates fall outside the editor or the editor has no model.
811-
*/
812-
getTargetAtClientPoint(clientX: number, clientY: number): IMouseTarget;
813-
814806
/**
815807
* Get the visible position for `position`.
816808
* The result position takes scrolling into account and is relative to the top left corner of the editor.

src/vs/editor/browser/widget/codeEditorWidget.ts

Lines changed: 44 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -201,28 +201,27 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
201201
public readonly isSimpleWidget: boolean;
202202
private readonly _telemetryData: object | null;
203203

204-
private readonly domElement: HTMLElement;
205-
private readonly id: number;
204+
private readonly _domElement: HTMLElement;
205+
private readonly _id: number;
206206
private readonly _configuration: editorCommon.IConfiguration;
207207

208-
protected _contributions: { [key: string]: editorCommon.IEditorContribution; };
209-
protected _actions: { [key: string]: editorCommon.IEditorAction; };
208+
protected readonly _contributions: { [key: string]: editorCommon.IEditorContribution; };
209+
protected readonly _actions: { [key: string]: editorCommon.IEditorAction; };
210210

211211
// --- Members logically associated to a model
212212
protected _modelData: ModelData | null;
213213

214-
215214
protected readonly _instantiationService: IInstantiationService;
216215
protected readonly _contextKeyService: IContextKeyService;
217216
private readonly _notificationService: INotificationService;
218217
private readonly _codeEditorService: ICodeEditorService;
219218
private readonly _commandService: ICommandService;
220219
private readonly _themeService: IThemeService;
221220

222-
private _focusTracker: CodeEditorWidgetFocusTracker;
221+
private readonly _focusTracker: CodeEditorWidgetFocusTracker;
223222

224-
private contentWidgets: { [key: string]: IContentWidgetData; };
225-
private overlayWidgets: { [key: string]: IOverlayWidgetData; };
223+
private readonly _contentWidgets: { [key: string]: IContentWidgetData; };
224+
private readonly _overlayWidgets: { [key: string]: IOverlayWidgetData; };
226225

227226
/**
228227
* map from "parent" decoration type to live decoration ids.
@@ -242,8 +241,8 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
242241
@INotificationService notificationService: INotificationService
243242
) {
244243
super();
245-
this.domElement = domElement;
246-
this.id = (++EDITOR_ID);
244+
this._domElement = domElement;
245+
this._id = (++EDITOR_ID);
247246
this._decorationTypeKeysToIds = {};
248247
this._decorationTypeSubtypes = {};
249248
this.isSimpleWidget = codeEditorWidgetOptions.isSimpleWidget || false;
@@ -258,13 +257,13 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
258257
this._onDidLayoutChange.fire(this._configuration.editor.layoutInfo);
259258
}
260259
if (this._configuration.editor.showUnused) {
261-
this.domElement.classList.add(SHOW_UNUSED_ENABLED_CLASS);
260+
this._domElement.classList.add(SHOW_UNUSED_ENABLED_CLASS);
262261
} else {
263-
this.domElement.classList.remove(SHOW_UNUSED_ENABLED_CLASS);
262+
this._domElement.classList.remove(SHOW_UNUSED_ENABLED_CLASS);
264263
}
265264
}));
266265

267-
this._contextKeyService = this._register(contextKeyService.createScoped(this.domElement));
266+
this._contextKeyService = this._register(contextKeyService.createScoped(this._domElement));
268267
this._notificationService = notificationService;
269268
this._codeEditorService = codeEditorService;
270269
this._commandService = commandService;
@@ -284,8 +283,8 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
284283
this._editorWidgetFocus.setValue(this._focusTracker.hasFocus());
285284
});
286285

287-
this.contentWidgets = {};
288-
this.overlayWidgets = {};
286+
this._contentWidgets = {};
287+
this._overlayWidgets = {};
289288

290289
mark('editor/start/contrib');
291290
let contributions: IEditorContributionCtor[];
@@ -325,11 +324,11 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
325324
}
326325

327326
protected _createConfiguration(options: editorOptions.IEditorOptions): editorCommon.IConfiguration {
328-
return new Configuration(options, this.domElement);
327+
return new Configuration(options, this._domElement);
329328
}
330329

331330
public getId(): string {
332-
return this.getEditorType() + ':' + this.id;
331+
return this.getEditorType() + ':' + this._id;
333332
}
334333

335334
public getEditorType(): string {
@@ -339,20 +338,14 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
339338
public dispose(): void {
340339
this._codeEditorService.removeCodeEditor(this);
341340

342-
this.contentWidgets = {};
343-
this.overlayWidgets = {};
344-
345341
this._focusTracker.dispose();
346342

347343
let keys = Object.keys(this._contributions);
348344
for (let i = 0, len = keys.length; i < len; i++) {
349345
let contributionId = keys[i];
350346
this._contributions[contributionId].dispose();
351347
}
352-
this._contributions = {};
353348

354-
// editor actions don't need to be disposed
355-
this._actions = {};
356349
this._removeDecorationTypes();
357350
this._postDetachModelCleanup(this._detachModel());
358351

@@ -1026,14 +1019,14 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
10261019
// callback will not be called
10271020
return null;
10281021
}
1029-
return this._modelData.model.changeDecorations(callback, this.id);
1022+
return this._modelData.model.changeDecorations(callback, this._id);
10301023
}
10311024

10321025
public getLineDecorations(lineNumber: number): IModelDecoration[] | null {
10331026
if (!this._modelData) {
10341027
return null;
10351028
}
1036-
return this._modelData.model.getLineDecorations(lineNumber, this.id, this._configuration.editor.readOnly);
1029+
return this._modelData.model.getLineDecorations(lineNumber, this._id, this._configuration.editor.readOnly);
10371030
}
10381031

10391032
public deltaDecorations(oldDecorations: string[], newDecorations: IModelDeltaDecoration[]): string[] {
@@ -1045,7 +1038,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
10451038
return oldDecorations;
10461039
}
10471040

1048-
return this._modelData.model.deltaDecorations(oldDecorations, newDecorations, this.id);
1041+
return this._modelData.model.deltaDecorations(oldDecorations, newDecorations, this._id);
10491042
}
10501043

10511044
public setDecorations(decorationTypeKey: string, decorationOptions: editorCommon.IDecorationOptions[]): void {
@@ -1178,11 +1171,11 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
11781171
position: widget.getPosition()
11791172
};
11801173

1181-
if (this.contentWidgets.hasOwnProperty(widget.getId())) {
1174+
if (this._contentWidgets.hasOwnProperty(widget.getId())) {
11821175
console.warn('Overwriting a content widget with the same id.');
11831176
}
11841177

1185-
this.contentWidgets[widget.getId()] = widgetData;
1178+
this._contentWidgets[widget.getId()] = widgetData;
11861179

11871180
if (this._modelData && this._modelData.hasRealView) {
11881181
this._modelData.view.addContentWidget(widgetData);
@@ -1191,8 +1184,8 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
11911184

11921185
public layoutContentWidget(widget: editorBrowser.IContentWidget): void {
11931186
let widgetId = widget.getId();
1194-
if (this.contentWidgets.hasOwnProperty(widgetId)) {
1195-
let widgetData = this.contentWidgets[widgetId];
1187+
if (this._contentWidgets.hasOwnProperty(widgetId)) {
1188+
let widgetData = this._contentWidgets[widgetId];
11961189
widgetData.position = widget.getPosition();
11971190
if (this._modelData && this._modelData.hasRealView) {
11981191
this._modelData.view.layoutContentWidget(widgetData);
@@ -1202,9 +1195,9 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
12021195

12031196
public removeContentWidget(widget: editorBrowser.IContentWidget): void {
12041197
let widgetId = widget.getId();
1205-
if (this.contentWidgets.hasOwnProperty(widgetId)) {
1206-
let widgetData = this.contentWidgets[widgetId];
1207-
delete this.contentWidgets[widgetId];
1198+
if (this._contentWidgets.hasOwnProperty(widgetId)) {
1199+
let widgetData = this._contentWidgets[widgetId];
1200+
delete this._contentWidgets[widgetId];
12081201
if (this._modelData && this._modelData.hasRealView) {
12091202
this._modelData.view.removeContentWidget(widgetData);
12101203
}
@@ -1217,11 +1210,11 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
12171210
position: widget.getPosition()
12181211
};
12191212

1220-
if (this.overlayWidgets.hasOwnProperty(widget.getId())) {
1213+
if (this._overlayWidgets.hasOwnProperty(widget.getId())) {
12211214
console.warn('Overwriting an overlay widget with the same id.');
12221215
}
12231216

1224-
this.overlayWidgets[widget.getId()] = widgetData;
1217+
this._overlayWidgets[widget.getId()] = widgetData;
12251218

12261219
if (this._modelData && this._modelData.hasRealView) {
12271220
this._modelData.view.addOverlayWidget(widgetData);
@@ -1230,8 +1223,8 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
12301223

12311224
public layoutOverlayWidget(widget: editorBrowser.IOverlayWidget): void {
12321225
let widgetId = widget.getId();
1233-
if (this.overlayWidgets.hasOwnProperty(widgetId)) {
1234-
let widgetData = this.overlayWidgets[widgetId];
1226+
if (this._overlayWidgets.hasOwnProperty(widgetId)) {
1227+
let widgetData = this._overlayWidgets[widgetId];
12351228
widgetData.position = widget.getPosition();
12361229
if (this._modelData && this._modelData.hasRealView) {
12371230
this._modelData.view.layoutOverlayWidget(widgetData);
@@ -1241,9 +1234,9 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
12411234

12421235
public removeOverlayWidget(widget: editorBrowser.IOverlayWidget): void {
12431236
let widgetId = widget.getId();
1244-
if (this.overlayWidgets.hasOwnProperty(widgetId)) {
1245-
let widgetData = this.overlayWidgets[widgetId];
1246-
delete this.overlayWidgets[widgetId];
1237+
if (this._overlayWidgets.hasOwnProperty(widgetId)) {
1238+
let widgetData = this._overlayWidgets[widgetId];
1239+
delete this._overlayWidgets[widgetId];
12471240
if (this._modelData && this._modelData.hasRealView) {
12481241
this._modelData.view.removeOverlayWidget(widgetData);
12491242
}
@@ -1311,17 +1304,17 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
13111304

13121305
const listenersToRemove: IDisposable[] = [];
13131306

1314-
this.domElement.setAttribute('data-mode-id', model.getLanguageIdentifier().language);
1307+
this._domElement.setAttribute('data-mode-id', model.getLanguageIdentifier().language);
13151308
this._configuration.setIsDominatedByLongLines(model.isDominatedByLongLines());
13161309
this._configuration.setMaxLineNumber(model.getLineCount());
13171310

13181311
model.onBeforeAttached();
13191312

1320-
const viewModel = new ViewModel(this.id, this._configuration, model, (callback) => dom.scheduleAtNextAnimationFrame(callback));
1313+
const viewModel = new ViewModel(this._id, this._configuration, model, (callback) => dom.scheduleAtNextAnimationFrame(callback));
13211314

13221315
listenersToRemove.push(model.onDidChangeDecorations((e) => this._onDidChangeModelDecorations.fire(e)));
13231316
listenersToRemove.push(model.onDidChangeLanguage((e) => {
1324-
this.domElement.setAttribute('data-mode-id', model.getLanguageIdentifier().language);
1317+
this._domElement.setAttribute('data-mode-id', model.getLanguageIdentifier().language);
13251318
this._onDidChangeModelLanguage.fire(e);
13261319
}));
13271320
listenersToRemove.push(model.onDidChangeLanguageConfiguration((e) => this._onDidChangeModelLanguageConfiguration.fire(e)));
@@ -1365,18 +1358,18 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
13651358

13661359
const [view, hasRealView] = this._createView(viewModel, cursor);
13671360
if (hasRealView) {
1368-
this.domElement.appendChild(view.domNode.domNode);
1361+
this._domElement.appendChild(view.domNode.domNode);
13691362

1370-
let keys = Object.keys(this.contentWidgets);
1363+
let keys = Object.keys(this._contentWidgets);
13711364
for (let i = 0, len = keys.length; i < len; i++) {
13721365
let widgetId = keys[i];
1373-
view.addContentWidget(this.contentWidgets[widgetId]);
1366+
view.addContentWidget(this._contentWidgets[widgetId]);
13741367
}
13751368

1376-
keys = Object.keys(this.overlayWidgets);
1369+
keys = Object.keys(this._overlayWidgets);
13771370
for (let i = 0, len = keys.length; i < len; i++) {
13781371
let widgetId = keys[i];
1379-
view.addOverlayWidget(this.overlayWidgets[widgetId]);
1372+
view.addOverlayWidget(this._overlayWidgets[widgetId]);
13801373
}
13811374

13821375
view.render(false, true);
@@ -1479,7 +1472,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
14791472

14801473
protected _postDetachModelCleanup(detachedModel: ITextModel | null): void {
14811474
if (detachedModel) {
1482-
detachedModel.removeAllDecorationsWithOwnerId(this.id);
1475+
detachedModel.removeAllDecorationsWithOwnerId(this._id);
14831476
}
14841477
}
14851478

@@ -1493,9 +1486,9 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
14931486
this._modelData.dispose();
14941487
this._modelData = null;
14951488

1496-
this.domElement.removeAttribute('data-mode-id');
1489+
this._domElement.removeAttribute('data-mode-id');
14971490
if (removeDomNode) {
1498-
this.domElement.removeChild(removeDomNode);
1491+
this._domElement.removeChild(removeDomNode);
14991492
}
15001493

15011494
return model;

0 commit comments

Comments
 (0)