Skip to content

Commit 481e001

Browse files
committed
Strict null checks
microsoft#60565
1 parent 33d86f1 commit 481e001

9 files changed

Lines changed: 110 additions & 71 deletions

File tree

src/tsconfig.strictNullChecks.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"./vs/base/node/id.ts",
5151
"./vs/base/node/paths.ts",
5252
"./vs/base/node/ports.ts",
53+
"./vs/base/node/processes.ts",
5354
"./vs/base/node/proxy.ts",
5455
"./vs/base/node/request.ts",
5556
"./vs/base/node/stats.ts",
@@ -62,6 +63,8 @@
6263
"./vs/base/parts/ipc/test/node/testService.ts",
6364
"./vs/base/parts/quickopen/common/quickOpen.ts",
6465
"./vs/base/test/common/utils.ts",
66+
"./vs/base/test/node/processes/fixtures/fork.ts",
67+
"./vs/base/test/node/processes/fixtures/fork_large.ts",
6568
"./vs/base/test/node/uri.test.perf.ts",
6669
"./vs/base/worker/defaultWorkerFactory.ts",
6770
"./vs/base/worker/workerMain.ts",
@@ -240,6 +243,7 @@
240243
"./vs/editor/contrib/comment/comment.ts",
241244
"./vs/editor/contrib/comment/lineCommentCommand.ts",
242245
"./vs/editor/contrib/cursorUndo/cursorUndo.ts",
246+
"./vs/editor/contrib/dnd/dnd.ts",
243247
"./vs/editor/contrib/dnd/dragAndDropCommand.ts",
244248
"./vs/editor/contrib/find/findDecorations.ts",
245249
"./vs/editor/contrib/find/findModel.ts",
@@ -273,19 +277,23 @@
273277
"./vs/editor/contrib/linesOperations/sortLinesCommand.ts",
274278
"./vs/editor/contrib/links/getLinks.ts",
275279
"./vs/editor/contrib/links/links.ts",
280+
"./vs/editor/contrib/markdown/markdownRenderer.ts",
276281
"./vs/editor/contrib/message/messageController.ts",
277282
"./vs/editor/contrib/parameterHints/provideSignatureHelp.ts",
278283
"./vs/editor/contrib/quickOpen/quickOpen.ts",
279284
"./vs/editor/contrib/referenceSearch/referencesModel.ts",
285+
"./vs/editor/contrib/rename/renameInputField.ts",
280286
"./vs/editor/contrib/smartSelect/tokenTree.ts",
281287
"./vs/editor/contrib/snippet/snippetParser.ts",
282288
"./vs/editor/contrib/suggest/suggest.ts",
283289
"./vs/editor/contrib/suggest/wordContextKey.ts",
284290
"./vs/editor/contrib/suggest/wordDistance.ts",
285291
"./vs/editor/contrib/toggleTabFocusMode/toggleTabFocusMode.ts",
286292
"./vs/editor/contrib/wordHighlighter/wordHighlighter.ts",
293+
"./vs/editor/contrib/wordOperations/test/wordTestUtils.ts",
287294
"./vs/editor/contrib/wordOperations/wordOperations.ts",
288295
"./vs/editor/contrib/wordPartOperations/wordPartOperations.ts",
296+
"./vs/editor/contrib/zoneWidget/zoneWidget.ts",
289297
"./vs/editor/editor.worker.ts",
290298
"./vs/editor/standalone/browser/colorizer.ts",
291299
"./vs/editor/standalone/browser/iPadShowKeyboard/iPadShowKeyboard.ts",
@@ -300,6 +308,7 @@
300308
"./vs/editor/standalone/common/themes.ts",
301309
"./vs/editor/test/browser/controller/imeTester.ts",
302310
"./vs/editor/test/browser/editorTestServices.ts",
311+
"./vs/editor/test/browser/testCodeEditor.ts",
303312
"./vs/editor/test/browser/view/minimapFontCreator.ts",
304313
"./vs/editor/test/common/commentMode.ts",
305314
"./vs/editor/test/common/core/viewLineToken.ts",
@@ -389,6 +398,7 @@
389398
"./vs/platform/state/common/state.ts",
390399
"./vs/platform/statusbar/common/statusbar.ts",
391400
"./vs/platform/storage/common/storage.ts",
401+
"./vs/platform/storage/common/storageLegacyService.ts",
392402
"./vs/platform/telemetry/browser/errorTelemetry.ts",
393403
"./vs/platform/telemetry/common/telemetry.ts",
394404
"./vs/platform/telemetry/common/telemetryService.ts",

src/vs/base/node/processes.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ export abstract class AbstractProcess<TProgressData> {
7676
private options: CommandOptions | ForkOptions;
7777
protected shell: boolean;
7878

79-
private childProcess: cp.ChildProcess;
80-
protected childProcessPromise: TPromise<cp.ChildProcess>;
81-
private pidResolve: TValueCallback<number>;
79+
private childProcess: cp.ChildProcess | null;
80+
protected childProcessPromise: TPromise<cp.ChildProcess> | null;
81+
private pidResolve?: TValueCallback<number>;
8282
protected terminateRequested: boolean;
8383

8484
private static WellKnowCommands: IStringDictionary<boolean> = {
@@ -103,7 +103,7 @@ export abstract class AbstractProcess<TProgressData> {
103103
};
104104

105105
public constructor(executable: Executable);
106-
public constructor(cmd: string, args: string[], shell: boolean, options: CommandOptions);
106+
public constructor(cmd: string, args: string[] | undefined, shell: boolean, options: CommandOptions | undefined);
107107
public constructor(arg1: string | Executable, arg2?: string[], arg3?: boolean, arg4?: CommandOptions) {
108108
if (arg2 !== void 0 && arg3 !== void 0 && arg4 !== void 0) {
109109
this.cmd = <string>arg1;
@@ -124,10 +124,10 @@ export abstract class AbstractProcess<TProgressData> {
124124
if (this.options.env) {
125125
let newEnv: IStringDictionary<string> = Object.create(null);
126126
Object.keys(process.env).forEach((key) => {
127-
newEnv[key] = process.env[key];
127+
newEnv[key] = process.env[key]!;
128128
});
129129
Object.keys(this.options.env).forEach((key) => {
130-
newEnv[key] = this.options.env[key];
130+
newEnv[key] = this.options.env![key]!;
131131
});
132132
this.options.env = newEnv;
133133
}
@@ -146,7 +146,7 @@ export abstract class AbstractProcess<TProgressData> {
146146
}
147147

148148
public start(pp: TProgressCallback<TProgressData>): TPromise<SuccessData> {
149-
if (Platform.isWindows && ((this.options && this.options.cwd && TPath.isUNC(this.options.cwd)) || !this.options && !this.options.cwd && TPath.isUNC(process.cwd()))) {
149+
if (Platform.isWindows && ((this.options && this.options.cwd && TPath.isUNC(this.options.cwd)) || !this.options && TPath.isUNC(process.cwd()))) {
150150
return TPromise.wrapError(new Error(nls.localize('TaskRunner.UNC', 'Can\'t execute a shell command on a UNC drive.')));
151151
}
152152
return this.useExec().then((useExec) => {
@@ -175,7 +175,7 @@ export abstract class AbstractProcess<TProgressData> {
175175
}
176176
});
177177
} else {
178-
let childProcess: cp.ChildProcess = null;
178+
let childProcess: cp.ChildProcess | null = null;
179179
let closeHandler = (data: any) => {
180180
this.childProcess = null;
181181
this.childProcessPromise = null;
@@ -239,15 +239,15 @@ export abstract class AbstractProcess<TProgressData> {
239239
});
240240
if (childProcess.pid) {
241241
this.childProcess.on('close', closeHandler);
242-
this.handleSpawn(childProcess, cc, pp, ee, true);
242+
this.handleSpawn(childProcess, cc!, pp, ee!, true);
243243
}
244244
}
245245
}
246246
return result;
247247
});
248248
}
249249

250-
protected abstract handleExec(cc: TValueCallback<SuccessData>, pp: TProgressCallback<TProgressData>, error: Error, stdout: Buffer, stderr: Buffer): void;
250+
protected abstract handleExec(cc: TValueCallback<SuccessData>, pp: TProgressCallback<TProgressData>, error: Error | null, stdout: Buffer, stderr: Buffer): void;
251251
protected abstract handleSpawn(childProcess: cp.ChildProcess, cc: TValueCallback<SuccessData>, pp: TProgressCallback<TProgressData>, ee: ErrorCallback, sync: boolean): void;
252252

253253
protected handleClose(data: any, cc: TValueCallback<SuccessData>, pp: TProgressCallback<TProgressData>, ee: ErrorCallback): void {

src/vs/editor/contrib/dnd/dnd.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class DragAndDropController implements editorCommon.IEditorContribution {
3434

3535
private _editor: ICodeEditor;
3636
private _toUnhook: IDisposable[];
37-
private _dragSelection: Selection;
37+
private _dragSelection: Selection | null;
3838
private _dndDecorationIds: string[];
3939
private _mouseDown: boolean;
4040
private _modiferPressed: boolean;
@@ -115,7 +115,8 @@ export class DragAndDropController implements editorCommon.IEditorContribution {
115115
let target = mouseEvent.target;
116116

117117
if (this._dragSelection === null) {
118-
let possibleSelections = this._editor.getSelections().filter(selection => selection.containsPosition(target.position));
118+
const selections = this._editor.getSelections() || [];
119+
let possibleSelections = selections.filter(selection => target.position && selection.containsPosition(target.position));
119120
if (possibleSelections.length === 1) {
120121
this._dragSelection = possibleSelections[0];
121122
} else {
@@ -133,10 +134,12 @@ export class DragAndDropController implements editorCommon.IEditorContribution {
133134
});
134135
}
135136

136-
if (this._dragSelection.containsPosition(target.position)) {
137-
this._removeDecoration();
138-
} else {
139-
this.showAt(target.position);
137+
if (target.position) {
138+
if (this._dragSelection.containsPosition(target.position)) {
139+
this._removeDecoration();
140+
} else {
141+
this.showAt(target.position);
142+
}
140143
}
141144
}
142145

@@ -148,10 +151,12 @@ export class DragAndDropController implements editorCommon.IEditorContribution {
148151
let newSelections: Selection[] | null = null;
149152
if (mouseEvent.event.shiftKey) {
150153
let primarySelection = this._editor.getSelection();
151-
let { selectionStartLineNumber, selectionStartColumn } = primarySelection;
152-
newSelections = [new Selection(selectionStartLineNumber, selectionStartColumn, newCursorPosition.lineNumber, newCursorPosition.column)];
154+
if (primarySelection) {
155+
const { selectionStartLineNumber, selectionStartColumn } = primarySelection;
156+
newSelections = [new Selection(selectionStartLineNumber, selectionStartColumn, newCursorPosition.lineNumber, newCursorPosition.column)];
157+
}
153158
} else {
154-
newSelections = this._editor.getSelections().map(selection => {
159+
newSelections = (this._editor.getSelections() || []).map(selection => {
155160
if (selection.containsPosition(newCursorPosition)) {
156161
return new Selection(newCursorPosition.lineNumber, newCursorPosition.column, newCursorPosition.lineNumber, newCursorPosition.column);
157162
} else {
@@ -160,7 +165,7 @@ export class DragAndDropController implements editorCommon.IEditorContribution {
160165
});
161166
}
162167
// Use `mouse` as the source instead of `api`.
163-
(<CodeEditorWidget>this._editor).setSelections(newSelections, 'mouse');
168+
(<CodeEditorWidget>this._editor).setSelections(newSelections || [], 'mouse');
164169
} else if (!this._dragSelection.containsPosition(newCursorPosition) ||
165170
(
166171
(

src/vs/editor/contrib/markdown/markdownRenderer.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,36 @@ export class MarkdownRenderer {
3838
// In markdown,
3939
// it is possible that we stumble upon language aliases (e.g.js instead of javascript)
4040
// it is possible no alias is given in which case we fall back to the current editor lang
41-
const modeId = languageAlias
42-
? this._modeService.getModeIdForLanguageName(languageAlias)
43-
: this._editor.getModel().getLanguageIdentifier().language;
41+
let modeId: string | null = null;
42+
if (languageAlias) {
43+
modeId = this._modeService.getModeIdForLanguageName(languageAlias);
44+
} else {
45+
const model = this._editor.getModel();
46+
if (model) {
47+
modeId = model.getLanguageIdentifier().language;
48+
}
49+
}
4450

45-
return this._modeService.getOrCreateMode(modeId).then(_ => {
46-
const promise = TokenizationRegistry.getPromise(modeId);
51+
return this._modeService.getOrCreateMode(modeId || '').then(_ => {
52+
const promise = TokenizationRegistry.getPromise(modeId || '');
4753
if (promise) {
4854
return promise.then(support => tokenizeToString(value, support));
4955
}
50-
return tokenizeToString(value, null);
56+
return tokenizeToString(value, undefined);
5157
}).then(code => {
5258
return `<span style="font-family: ${this._editor.getConfiguration().fontInfo.fontFamily}">${code}</span>`;
5359
});
5460
},
5561
codeBlockRenderCallback: () => this._onDidRenderCodeBlock.fire(),
5662
actionHandler: {
5763
callback: (content) => {
58-
let uri: URI;
64+
let uri: URI | undefined;
5965
try {
6066
uri = URI.parse(content);
61-
} catch (err) {
67+
} catch {
6268
// ignore
6369
}
64-
if (uri) {
70+
if (uri && this._openerService) {
6571
this._openerService.open(uri).catch(onUnexpectedError);
6672
}
6773
},

src/vs/editor/contrib/rename/renameInputField.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ export default class RenameInputField implements IContentWidget, IDisposable {
9999
this._inputField.style.fontSize = `${fontInfo.fontSize}px`;
100100
}
101101

102-
public getPosition(): IContentWidgetPosition {
102+
public getPosition(): IContentWidgetPosition | null {
103103
return this._visible
104104
? { position: this._position, preference: [ContentWidgetPositionPreference.BELOW, ContentWidgetPositionPreference.ABOVE] }
105105
: null;
106106
}
107107

108-
private _currentAcceptInput: () => void = null;
109-
private _currentCancelInput: (focusEditor) => void = null;
108+
private _currentAcceptInput: (() => void) | null = null;
109+
private _currentCancelInput: ((focusEditor) => void) | null = null;
110110

111111
public acceptInput(): void {
112112
if (this._currentAcceptInput) {
@@ -158,7 +158,8 @@ export default class RenameInputField implements IContentWidget, IDisposable {
158158
};
159159

160160
let onCursorChanged = () => {
161-
if (!Range.containsPosition(where, this._editor.getPosition())) {
161+
const editorPosition = this._editor.getPosition();
162+
if (!editorPosition || !Range.containsPosition(where, editorPosition)) {
162163
this.cancelInput(true);
163164
}
164165
};
@@ -185,8 +186,8 @@ export default class RenameInputField implements IContentWidget, IDisposable {
185186
setTimeout(() => {
186187
this._inputField.focus();
187188
this._inputField.setSelectionRange(
188-
parseInt(this._inputField.getAttribute('selectionStart')),
189-
parseInt(this._inputField.getAttribute('selectionEnd')));
189+
parseInt(this._inputField.getAttribute('selectionStart')!),
190+
parseInt(this._inputField.getAttribute('selectionEnd')!));
190191
}, 100);
191192
}
192193

0 commit comments

Comments
 (0)