Skip to content

Commit 8df9f24

Browse files
committed
Strict null checks
1 parent 2181690 commit 8df9f24

10 files changed

Lines changed: 49 additions & 27 deletions

File tree

src/tsconfig.strictNullChecks.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
"./vs/code/electron-browser/issue/issueReporterUtil.ts",
9393
"./vs/code/electron-main/auth.ts",
9494
"./vs/code/electron-main/keyboard.ts",
95+
"./vs/code/electron-main/sharedProcess.ts",
9596
"./vs/code/electron-main/theme.ts",
9697
"./vs/code/node/shellEnv.ts",
9798
"./vs/editor/browser/config/charWidthReader.ts",
@@ -259,6 +260,7 @@
259260
"./vs/editor/contrib/codeAction/codeActionModel.ts",
260261
"./vs/editor/contrib/codeAction/codeActionTrigger.ts",
261262
"./vs/editor/contrib/codeAction/lightBulbWidget.ts",
263+
"./vs/editor/contrib/codelens/codelens.ts",
262264
"./vs/editor/contrib/colorPicker/color.ts",
263265
"./vs/editor/contrib/colorPicker/colorDetector.ts",
264266
"./vs/editor/contrib/colorPicker/colorPickerModel.ts",
@@ -290,6 +292,7 @@
290292
"./vs/editor/contrib/fontZoom/fontZoom.ts",
291293
"./vs/editor/contrib/goToDefinition/clickLinkGesture.ts",
292294
"./vs/editor/contrib/goToDefinition/goToDefinition.ts",
295+
"./vs/editor/contrib/gotoError/gotoErrorWidget.ts",
293296
"./vs/editor/contrib/hover/getHover.ts",
294297
"./vs/editor/contrib/hover/hoverOperation.ts",
295298
"./vs/editor/contrib/hover/hoverWidgets.ts",
@@ -335,6 +338,7 @@
335338
"./vs/editor/test/browser/controller/imeTester.ts",
336339
"./vs/editor/test/browser/editorTestServices.ts",
337340
"./vs/editor/test/browser/testCodeEditor.ts",
341+
"./vs/editor/test/browser/testCommand.ts",
338342
"./vs/editor/test/browser/view/minimapFontCreator.ts",
339343
"./vs/editor/test/common/commentMode.ts",
340344
"./vs/editor/test/common/core/viewLineToken.ts",
@@ -503,7 +507,7 @@
503507
"./vs/workbench/parts/codeEditor/electron-browser/toggleWordWrap.ts",
504508
"./vs/workbench/parts/comments/common/commentModel.ts",
505509
"./vs/workbench/parts/comments/electron-browser/commentGlyphWidget.ts",
506-
"vs/workbench/parts/comments/electron-browser/commentService.ts",
510+
"./vs/workbench/parts/comments/electron-browser/commentService.ts",
507511
"./vs/workbench/parts/emmet/browser/actions/showEmmetCommands.ts",
508512
"./vs/workbench/parts/emmet/browser/emmet.browser.contribution.ts",
509513
"./vs/workbench/parts/emmet/electron-browser/actions/expandAbbreviation.ts",
@@ -537,11 +541,13 @@
537541
"./vs/workbench/parts/surveys/electron-browser/nps.contribution.ts",
538542
"./vs/workbench/parts/tasks/common/problemCollectors.ts",
539543
"./vs/workbench/parts/tasks/common/problemMatcher.ts",
544+
"./vs/workbench/parts/tasks/common/taskDefinitionRegistry.ts",
540545
"./vs/workbench/parts/tasks/common/taskService.ts",
541546
"./vs/workbench/parts/tasks/common/taskSystem.ts",
542547
"./vs/workbench/parts/tasks/common/taskTemplates.ts",
543548
"./vs/workbench/parts/tasks/common/tasks.ts",
544549
"./vs/workbench/parts/tasks/electron-browser/jsonSchemaCommon.ts",
550+
"./vs/workbench/parts/tasks/node/tasks.ts",
545551
"./vs/workbench/parts/terminal/browser/terminalTab.ts",
546552
"./vs/workbench/parts/terminal/browser/terminalWidgetManager.ts",
547553
"./vs/workbench/parts/terminal/common/terminal.ts",
@@ -591,6 +597,7 @@
591597
"./vs/workbench/services/keybinding/common/macLinuxKeyboardMapper.ts",
592598
"./vs/workbench/services/keybinding/common/windowsKeyboardMapper.ts",
593599
"./vs/workbench/services/mode/common/workbenchModeService.ts",
600+
"./vs/workbench/services/notification/common/notificationService.ts",
594601
"./vs/workbench/services/panel/common/panelService.ts",
595602
"./vs/workbench/services/part/common/partService.ts",
596603
"./vs/workbench/services/scm/common/scm.ts",

src/vs/base/common/labels.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface IUserHomeProvider {
2424
/**
2525
* @deprecated use LabelService instead
2626
*/
27-
export function getPathLabel(resource: URI | string, userHomeProvider: IUserHomeProvider, rootProvider?: IWorkspaceFolderProvider): string {
27+
export function getPathLabel(resource: URI | string, userHomeProvider?: IUserHomeProvider, rootProvider?: IWorkspaceFolderProvider): string {
2828
if (typeof resource === 'string') {
2929
resource = URI.file(resource);
3030
}

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class SharedProcess implements ISharedProcess {
2121

2222
private barrier = new Barrier();
2323

24-
private window: Electron.BrowserWindow;
24+
private window: Electron.BrowserWindow | null;
2525

2626
constructor(
2727
private readonly machineId: string,
@@ -63,7 +63,7 @@ export class SharedProcess implements ISharedProcess {
6363
e.preventDefault();
6464

6565
// Still hide the window though if visible
66-
if (this.window.isVisible()) {
66+
if (this.window && this.window.isVisible()) {
6767
this.window.hide();
6868
}
6969
};
@@ -81,12 +81,16 @@ export class SharedProcess implements ISharedProcess {
8181
// Otherwise the application would never quit because the shared process
8282
// window is refusing to close!
8383
//
84-
this.window.removeListener('close', onClose);
84+
if (this.window) {
85+
this.window.removeListener('close', onClose);
86+
}
8587

8688
// Electron seems to crash on Windows without this setTimeout :|
8789
setTimeout(() => {
8890
try {
89-
this.window.close();
91+
if (this.window) {
92+
this.window.close();
93+
}
9094
} catch (err) {
9195
// ignore, as electron is already shutting down
9296
}
@@ -118,20 +122,24 @@ export class SharedProcess implements ISharedProcess {
118122
}
119123

120124
toggle(): void {
121-
if (this.window.isVisible()) {
125+
if (!this.window || this.window.isVisible()) {
122126
this.hide();
123127
} else {
124128
this.show();
125129
}
126130
}
127131

128132
show(): void {
129-
this.window.show();
130-
this.window.webContents.openDevTools();
133+
if (this.window) {
134+
this.window.show();
135+
this.window.webContents.openDevTools();
136+
}
131137
}
132138

133139
hide(): void {
134-
this.window.webContents.closeDevTools();
135-
this.window.hide();
140+
if (this.window) {
141+
this.window.webContents.closeDevTools();
142+
this.window.hide();
143+
}
136144
}
137145
}

src/vs/code/node/windowsFinder.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export interface IBestWindowOrFolderOptions<W extends ISimpleWindow> {
2929
workspaceResolver: (workspace: IWorkspaceIdentifier) => IResolvedWorkspace;
3030
}
3131

32-
export function findBestWindowOrFolderForFile<W extends ISimpleWindow>({ windows, newWindow, reuseWindow, context, fileUri, workspaceResolver }: IBestWindowOrFolderOptions<W>): W {
32+
export function findBestWindowOrFolderForFile<W extends ISimpleWindow>({ windows, newWindow, reuseWindow, context, fileUri, workspaceResolver }: IBestWindowOrFolderOptions<W>): W | null {
3333
if (!newWindow && fileUri && (context === OpenContext.DESKTOP || context === OpenContext.CLI || context === OpenContext.DOCK)) {
3434
const windowOnFilePath = findWindowOnFilePath(windows, fileUri, workspaceResolver);
3535
if (windowOnFilePath) {
@@ -39,7 +39,7 @@ export function findBestWindowOrFolderForFile<W extends ISimpleWindow>({ windows
3939
return !newWindow ? getLastActiveWindow(windows) : null;
4040
}
4141

42-
function findWindowOnFilePath<W extends ISimpleWindow>(windows: W[], fileUri: URI, workspaceResolver: (workspace: IWorkspaceIdentifier) => IResolvedWorkspace): W {
42+
function findWindowOnFilePath<W extends ISimpleWindow>(windows: W[], fileUri: URI, workspaceResolver: (workspace: IWorkspaceIdentifier) => IResolvedWorkspace): W | null {
4343

4444
// First check for windows with workspaces that have a parent folder of the provided path opened
4545
const workspaceWindows = windows.filter(window => !!window.openedWorkspace);
@@ -66,7 +66,7 @@ export function getLastActiveWindow<W extends ISimpleWindow>(windows: W[]): W {
6666
return windows.filter(window => window.lastFocusTime === lastFocusedDate)[0];
6767
}
6868

69-
export function findWindowOnWorkspace<W extends ISimpleWindow>(windows: W[], workspace: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier)): W {
69+
export function findWindowOnWorkspace<W extends ISimpleWindow>(windows: W[], workspace: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier)): W | null {
7070
if (isSingleFolderWorkspaceIdentifier(workspace)) {
7171
for (const window of windows) {
7272
// match on folder
@@ -87,7 +87,7 @@ export function findWindowOnWorkspace<W extends ISimpleWindow>(windows: W[], wor
8787
return null;
8888
}
8989

90-
export function findWindowOnExtensionDevelopmentPath<W extends ISimpleWindow>(windows: W[], extensionDevelopmentPath: string): W {
90+
export function findWindowOnExtensionDevelopmentPath<W extends ISimpleWindow>(windows: W[], extensionDevelopmentPath: string): W | null {
9191
for (const window of windows) {
9292
// match on extension development path. The path can be a path or uri string, using paths.isEqual is not 100% correct but good enough
9393
if (paths.isEqual(window.extensionDevelopmentPath, extensionDevelopmentPath, !platform.isLinux /* ignorecase */)) {
@@ -97,7 +97,7 @@ export function findWindowOnExtensionDevelopmentPath<W extends ISimpleWindow>(wi
9797
return null;
9898
}
9999

100-
export function findWindowOnWorkspaceOrFolderUri<W extends ISimpleWindow>(windows: W[], uri: URI): W {
100+
export function findWindowOnWorkspaceOrFolderUri<W extends ISimpleWindow>(windows: W[], uri: URI): W | null {
101101
if (!uri) {
102102
return null;
103103
}

src/vs/editor/contrib/codelens/codelens.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ registerLanguageCommand('_executeCodeLensProvider', function (accessor, args) {
7373
for (const item of value) {
7474
if (typeof itemResolveCount === 'undefined' || Boolean(item.symbol.command)) {
7575
result.push(item.symbol);
76-
} else if (itemResolveCount-- > 0) {
77-
resolve.push(Promise.resolve(item.provider.resolveCodeLens(model, item.symbol, CancellationToken.None)).then(symbol => result.push(symbol)));
76+
} else if (itemResolveCount-- > 0 && item.provider.resolveCodeLens) {
77+
resolve.push(Promise.resolve(item.provider.resolveCodeLens(model, item.symbol, CancellationToken.None)).then(symbol => result.push(symbol || item.symbol)));
7878
}
7979
}
8080

src/vs/editor/contrib/gotoError/gotoErrorWidget.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class MessageWidget {
111111
this._relatedBlock.style.paddingTop = `${Math.floor(this._editor.getConfiguration().lineHeight * .66)}px`;
112112
this._lines += 1;
113113

114-
for (const related of relatedInformation) {
114+
for (const related of relatedInformation || []) {
115115

116116
let container = document.createElement('div');
117117

@@ -159,7 +159,7 @@ export class MarkerNavigationWidget extends ZoneWidget {
159159
private _message: MessageWidget;
160160
private _callOnDispose: IDisposable[] = [];
161161
private _severity: MarkerSeverity;
162-
private _backgroundColor: Color;
162+
private _backgroundColor: Color | null;
163163
private _onDidSelectRelatedInformation = new Emitter<IRelatedInformation>();
164164

165165
readonly onDidSelectRelatedInformation: Event<IRelatedInformation> = this._onDidSelectRelatedInformation.event;
@@ -195,7 +195,7 @@ export class MarkerNavigationWidget extends ZoneWidget {
195195

196196
protected _applyStyles(): void {
197197
if (this._parentContainer) {
198-
this._parentContainer.style.backgroundColor = this._backgroundColor.toString();
198+
this._parentContainer.style.backgroundColor = this._backgroundColor ? this._backgroundColor.toString() : '';
199199
}
200200
super._applyStyles();
201201
}
@@ -244,7 +244,8 @@ export class MarkerNavigationWidget extends ZoneWidget {
244244

245245
// show
246246
let range = Range.lift(marker);
247-
let position = range.containsPosition(this.editor.getPosition()) ? this.editor.getPosition() : range.getStartPosition();
247+
const editorPosition = this.editor.getPosition();
248+
let position = editorPosition && range.containsPosition(editorPosition) ? editorPosition : range.getStartPosition();
248249
super.show(position, this.computeRequiredHeight());
249250

250251
this.editor.revealPositionInCenter(position, ScrollType.Smooth);

src/vs/editor/contrib/zoneWidget/zoneWidget.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ export interface IOptions {
3131
}
3232

3333
export interface IStyles {
34-
frameColor?: Color;
35-
arrowColor?: Color;
34+
frameColor?: Color | null;
35+
arrowColor?: Color | null;
3636
}
3737

3838
const defaultColor = new Color(new RGBA(0, 122, 204));

src/vs/editor/test/browser/testCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export function getEditOperation(model: ITextModel, command: editorCommon.IComma
6161

6262

6363
trackSelection: (selection: Selection) => {
64-
return null;
64+
return '';
6565
}
6666
};
6767
command.getEditOperations(model, editOperationBuilder);

src/vs/workbench/parts/tasks/common/taskDefinitionRegistry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace Configuration {
4646
properties?: IJSONSchemaMap;
4747
}
4848

49-
export function from(value: TaskDefinition, extensionId: string, messageCollector: ExtensionMessageCollector): Tasks.TaskDefinition {
49+
export function from(value: TaskDefinition, extensionId: string, messageCollector: ExtensionMessageCollector): Tasks.TaskDefinition | undefined {
5050
if (!value) {
5151
return undefined;
5252
}
@@ -137,7 +137,7 @@ class TaskDefinitionRegistryImpl implements ITaskDefinitionRegistry {
137137
} else {
138138
schema.properties = Object.create(null);
139139
}
140-
schema.properties.type = {
140+
schema.properties!.type = {
141141
type: 'string',
142142
enum: [definition.taskType]
143143
};

src/vs/workbench/services/notification/common/notificationService.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,14 @@ export class NotificationService extends Disposable implements INotificationServ
6363
choices.forEach((choice, index) => {
6464
const action = new ChoiceAction(`workbench.dialog.choice.${index}`, choice);
6565
if (!choice.isSecondary) {
66+
if (!actions.primary) {
67+
actions.primary = [];
68+
}
6669
actions.primary.push(action);
6770
} else {
71+
if (!actions.secondary) {
72+
actions.secondary = [];
73+
}
6874
actions.secondary.push(action);
6975
}
7076

0 commit comments

Comments
 (0)