Skip to content

Commit 7f7df37

Browse files
committed
Strict null checks
1 parent d79718a commit 7f7df37

7 files changed

Lines changed: 62 additions & 33 deletions

File tree

src/tsconfig.strictNullChecks.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@
9090
"./vs/code/electron-browser/issue/issueReporterModel.ts",
9191
"./vs/code/electron-browser/issue/issueReporterPage.ts",
9292
"./vs/code/electron-browser/issue/issueReporterUtil.ts",
93-
"./vs/code/electron-browser/processExplorer/processExplorerMain.ts",
9493
"./vs/code/electron-main/auth.ts",
9594
"./vs/code/electron-main/keyboard.ts",
9695
"./vs/code/electron-main/theme.ts",
@@ -257,6 +256,7 @@
257256
"./vs/editor/contrib/caretOperations/transpose.ts",
258257
"./vs/editor/contrib/clipboard/clipboard.ts",
259258
"./vs/editor/contrib/codeAction/codeAction.ts",
259+
"./vs/editor/contrib/codeAction/codeActionModel.ts",
260260
"./vs/editor/contrib/codeAction/codeActionTrigger.ts",
261261
"./vs/editor/contrib/colorPicker/color.ts",
262262
"./vs/editor/contrib/colorPicker/colorDetector.ts",
@@ -445,9 +445,11 @@
445445
"./vs/platform/theme/common/themeService.ts",
446446
"./vs/platform/theme/test/common/testThemeService.ts",
447447
"./vs/platform/update/common/update.ts",
448+
"./vs/platform/update/electron-main/abstractUpdateService.ts",
448449
"./vs/platform/update/node/update.config.contribution.ts",
449450
"./vs/platform/url/common/url.ts",
450451
"./vs/platform/url/common/urlService.ts",
452+
"./vs/platform/url/electron-main/electronUrlListener.ts",
451453
"./vs/platform/widget/common/contextScopedWidget.ts",
452454
"./vs/platform/windows/common/windows.ts",
453455
"./vs/platform/windows/electron-browser/windowService.ts",
@@ -524,6 +526,7 @@
524526
"./vs/workbench/parts/surveys/electron-browser/nps.contribution.ts",
525527
"./vs/workbench/parts/tasks/common/problemCollectors.ts",
526528
"./vs/workbench/parts/tasks/common/problemMatcher.ts",
529+
"./vs/workbench/parts/tasks/common/taskService.ts",
527530
"./vs/workbench/parts/tasks/common/taskSystem.ts",
528531
"./vs/workbench/parts/tasks/common/taskTemplates.ts",
529532
"./vs/workbench/parts/tasks/common/tasks.ts",

src/vs/code/electron-main/sharedProcess.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export class SharedProcess implements ISharedProcess {
9898
logLevel: this.logService.getLevel()
9999
});
100100

101-
ipcMain.once('handshake:im ready', () => c(null));
101+
ipcMain.once('handshake:im ready', () => c(void 0));
102102
});
103103
});
104104
}

src/vs/editor/contrib/codeAction/codeActionModel.ts

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,12 @@ export class CodeActionOracle {
4949
}
5050

5151
private _onMarkerChanges(resources: URI[]): void {
52-
const { uri } = this._editor.getModel();
53-
if (resources.some(resource => resource.toString() === uri.toString())) {
52+
const model = this._editor.getModel();
53+
if (!model) {
54+
return;
55+
}
56+
57+
if (resources.some(resource => resource.toString() === model.uri.toString())) {
5458
this._autoTriggerTimer.cancelAndSet(() => {
5559
this.trigger({ type: 'auto' });
5660
}, this._delay);
@@ -63,8 +67,11 @@ export class CodeActionOracle {
6367
}, this._delay);
6468
}
6569

66-
private _getRangeOfMarker(selection: Selection): Range {
70+
private _getRangeOfMarker(selection: Selection): Range | undefined {
6771
const model = this._editor.getModel();
72+
if (!model) {
73+
return undefined;
74+
}
6875
for (const marker of this._markerService.read({ resource: model.uri })) {
6976
if (Range.intersectRanges(marker, selection)) {
7077
return Range.lift(marker);
@@ -76,7 +83,7 @@ export class CodeActionOracle {
7683
private _getRangeOfSelectionUnlessWhitespaceEnclosed(trigger: CodeActionTrigger): Selection | undefined {
7784
const model = this._editor.getModel();
7885
const selection = this._editor.getSelection();
79-
if (selection.isEmpty() && !(trigger.filter && trigger.filter.includeSourceActions)) {
86+
if (model && selection && selection.isEmpty() && !(trigger.filter && trigger.filter.includeSourceActions)) {
8087
const { lineNumber, column } = selection.getPosition();
8188
const line = model.getLineContent(lineNumber);
8289
if (line.length === 0) {
@@ -99,7 +106,7 @@ export class CodeActionOracle {
99106
}
100107
}
101108
}
102-
return selection;
109+
return selection ? selection : undefined;
103110
}
104111

105112
private _createEventAndSignalChange(trigger: CodeActionTrigger, selection: Selection | undefined): Thenable<CodeAction[] | undefined> {
@@ -114,6 +121,17 @@ export class CodeActionOracle {
114121
return Promise.resolve(undefined);
115122
} else {
116123
const model = this._editor.getModel();
124+
if (!model) {
125+
// cancel
126+
this._signalChange({
127+
trigger,
128+
rangeOrSelection: undefined,
129+
position: undefined,
130+
actions: undefined,
131+
});
132+
return Promise.resolve(undefined);
133+
}
134+
117135
const markerRange = this._getRangeOfMarker(selection);
118136
const position = markerRange ? markerRange.getStartPosition() : selection.getStartPosition();
119137
const actions = createCancelablePromise(token => getCodeActions(model, selection, trigger, token));
@@ -135,16 +153,16 @@ export class CodeActionOracle {
135153

136154
export interface CodeActionsComputeEvent {
137155
trigger: CodeActionTrigger;
138-
rangeOrSelection: Range | Selection;
139-
position: Position;
140-
actions: CancelablePromise<CodeAction[]>;
156+
rangeOrSelection: Range | Selection | undefined;
157+
position: Position | undefined;
158+
actions: CancelablePromise<CodeAction[]> | undefined;
141159
}
142160

143161
export class CodeActionModel {
144162

145163
private _editor: ICodeEditor;
146164
private _markerService: IMarkerService;
147-
private _codeActionOracle: CodeActionOracle;
165+
private _codeActionOracle?: CodeActionOracle;
148166
private _onDidChangeFixes = new Emitter<CodeActionsComputeEvent>();
149167
private _disposables: IDisposable[] = [];
150168
private readonly _supportedCodeActions: IContextKey<string>;
@@ -179,12 +197,13 @@ export class CodeActionModel {
179197
this._onDidChangeFixes.fire(undefined);
180198
}
181199

182-
if (this._editor.getModel()
183-
&& CodeActionProviderRegistry.has(this._editor.getModel())
200+
const model = this._editor.getModel();
201+
if (model
202+
&& CodeActionProviderRegistry.has(model)
184203
&& !this._editor.getConfiguration().readOnly) {
185204

186205
const supportedActions: string[] = [];
187-
for (const provider of CodeActionProviderRegistry.all(this._editor.getModel())) {
206+
for (const provider of CodeActionProviderRegistry.all(model)) {
188207
if (Array.isArray(provider.providedCodeActionKinds)) {
189208
supportedActions.push(...provider.providedCodeActionKinds);
190209
}

src/vs/editor/contrib/codeAction/lightBulbWidget.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ export class LightBulbWidget implements IDisposable, IContentWidget {
2525

2626
readonly onClick: Event<{ x: number, y: number }> = this._onClick.event;
2727

28-
private _position: IContentWidgetPosition;
29-
private _model: CodeActionsComputeEvent;
28+
private _position: IContentWidgetPosition | null;
29+
private _model: CodeActionsComputeEvent | null;
3030
private _futureFixes = new CancellationTokenSource();
3131

3232
constructor(editor: ICodeEditor) {
@@ -40,7 +40,7 @@ export class LightBulbWidget implements IDisposable, IContentWidget {
4040
this._disposables.push(this._editor.onDidChangeModelLanguage(_ => this._futureFixes.cancel()));
4141
this._disposables.push(this._editor.onDidChangeModelContent(_ => {
4242
// cancel when the line in question has been removed
43-
if (this._model && this.model.position.lineNumber >= this._editor.getModel().getLineCount()) {
43+
if (this._model && (!this.model.position || this.model.position.lineNumber >= this._editor.getModel().getLineCount())) {
4444
this._futureFixes.cancel();
4545
}
4646
}));
@@ -96,7 +96,7 @@ export class LightBulbWidget implements IDisposable, IContentWidget {
9696
return this._domNode;
9797
}
9898

99-
getPosition(): IContentWidgetPosition {
99+
getPosition(): IContentWidgetPosition | null {
100100
return this._position;
101101
}
102102

@@ -126,7 +126,7 @@ export class LightBulbWidget implements IDisposable, IContentWidget {
126126
} else {
127127
this.hide();
128128
}
129-
}).catch(err => {
129+
}).catch(() => {
130130
this.hide();
131131
});
132132
}
@@ -148,6 +148,9 @@ export class LightBulbWidget implements IDisposable, IContentWidget {
148148
if (!config.contribInfo.lightbulbEnabled) {
149149
return;
150150
}
151+
if (!this._model.position) {
152+
return;
153+
}
151154
const { lineNumber, column } = this._model.position;
152155
const model = this._editor.getModel();
153156
if (!model) {

src/vs/platform/update/electron-main/abstractUpdateService.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ export abstract class AbstractUpdateService implements IUpdateService {
7474
this.setState(State.Idle(this.getUpdateType()));
7575

7676
// Start checking for updates after 30 seconds
77-
this.scheduleCheckForUpdates(30 * 1000).then(null, err => this.logService.error(err));
77+
this.scheduleCheckForUpdates(30 * 1000).then(undefined, err => this.logService.error(err));
7878
}
7979

80-
private getProductQuality(): string {
80+
private getProductQuality(): string | undefined {
8181
const quality = this.configurationService.getValue<string>('update.channel');
82-
return quality === 'none' ? null : product.quality;
82+
return quality === 'none' ? undefined : product.quality;
8383
}
8484

8585
private scheduleCheckForUpdates(delay = 60 * 60 * 1000): Thenable<void> {
@@ -95,7 +95,7 @@ export abstract class AbstractUpdateService implements IUpdateService {
9595
this.logService.trace('update#checkForUpdates, state = ', this.state.type);
9696

9797
if (this.state.type !== StateType.Idle) {
98-
return TPromise.as(null);
98+
return TPromise.as(void 0);
9999
}
100100

101101
return this.throttler.queue(() => TPromise.as(this.doCheckForUpdates(context)));
@@ -105,35 +105,35 @@ export abstract class AbstractUpdateService implements IUpdateService {
105105
this.logService.trace('update#downloadUpdate, state = ', this.state.type);
106106

107107
if (this.state.type !== StateType.AvailableForDownload) {
108-
return TPromise.as(null);
108+
return TPromise.as(void 0);
109109
}
110110

111111
return this.doDownloadUpdate(this.state);
112112
}
113113

114114
protected doDownloadUpdate(state: AvailableForDownload): TPromise<void> {
115-
return TPromise.as(null);
115+
return TPromise.as(void 0);
116116
}
117117

118118
applyUpdate(): TPromise<void> {
119119
this.logService.trace('update#applyUpdate, state = ', this.state.type);
120120

121121
if (this.state.type !== StateType.Downloaded) {
122-
return TPromise.as(null);
122+
return TPromise.as(void 0);
123123
}
124124

125125
return this.doApplyUpdate();
126126
}
127127

128128
protected doApplyUpdate(): TPromise<void> {
129-
return TPromise.as(null);
129+
return TPromise.as(void 0);
130130
}
131131

132132
quitAndInstall(): TPromise<void> {
133133
this.logService.trace('update#quitAndInstall, state = ', this.state.type);
134134

135135
if (this.state.type !== StateType.Ready) {
136-
return TPromise.as(null);
136+
return TPromise.as(void 0);
137137
}
138138

139139
this.logService.trace('update#quitAndInstall(): before lifecycle quit()');
@@ -148,7 +148,7 @@ export abstract class AbstractUpdateService implements IUpdateService {
148148
this.doQuitAndInstall();
149149
});
150150

151-
return TPromise.as(null);
151+
return TPromise.as(void 0);
152152
}
153153

154154
isLatestVersion(): TPromise<boolean | undefined> {

src/vs/platform/url/electron-main/electronUrlListener.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ export class ElectronURLListener {
3636
];
3737

3838
const buffer = rawBuffer.map(uriFromRawUrl).filter(uri => !!uri);
39-
const flush = () => buffer.forEach(uri => urlService.open(uri));
39+
const flush = () => buffer.forEach(uri => {
40+
if (uri) {
41+
urlService.open(uri);
42+
}
43+
});
4044

4145
app.setAsDefaultProtocolClient(product.urlProtocol, process.execPath, ['--open-url', '--']);
4246

src/vs/workbench/common/notifications.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export class NotificationsModel extends Disposable implements INotificationsMode
125125
}
126126
}
127127

128-
private findNotification(item: INotificationViewItem): INotificationViewItem {
128+
private findNotification(item: INotificationViewItem): INotificationViewItem | undefined {
129129
for (let i = 0; i < this._notifications.length; i++) {
130130
const notification = this._notifications[i];
131131
if (notification.equals(item)) {
@@ -136,7 +136,7 @@ export class NotificationsModel extends Disposable implements INotificationsMode
136136
return void 0;
137137
}
138138

139-
private createViewItem(notification: INotification): INotificationViewItem {
139+
private createViewItem(notification: INotification): INotificationViewItem | null {
140140
const item = NotificationViewItem.create(notification);
141141
if (!item) {
142142
return null;
@@ -340,7 +340,7 @@ export class NotificationViewItem extends Disposable implements INotificationVie
340340
private readonly _onDidLabelChange: Emitter<INotificationViewItemLabelChangeEvent> = this._register(new Emitter<INotificationViewItemLabelChangeEvent>());
341341
get onDidLabelChange(): Event<INotificationViewItemLabelChangeEvent> { return this._onDidLabelChange.event; }
342342

343-
static create(notification: INotification): INotificationViewItem {
343+
static create(notification: INotification): INotificationViewItem | null {
344344
if (!notification || !notification.message || isPromiseCanceledError(notification.message)) {
345345
return null; // we need a message to show
346346
}

0 commit comments

Comments
 (0)