From 8df9f241e6bf032013c4166100dbd83f584318ef Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Thu, 25 Oct 2018 16:03:07 -0700 Subject: [PATCH] Strict null checks --- src/tsconfig.strictNullChecks.json | 9 ++++++- src/vs/base/common/labels.ts | 2 +- src/vs/code/electron-main/sharedProcess.ts | 26 ++++++++++++------- src/vs/code/node/windowsFinder.ts | 10 +++---- src/vs/editor/contrib/codelens/codelens.ts | 4 +-- .../contrib/gotoError/gotoErrorWidget.ts | 9 ++++--- .../editor/contrib/zoneWidget/zoneWidget.ts | 4 +-- src/vs/editor/test/browser/testCommand.ts | 2 +- .../tasks/common/taskDefinitionRegistry.ts | 4 +-- .../common/notificationService.ts | 6 +++++ 10 files changed, 49 insertions(+), 27 deletions(-) diff --git a/src/tsconfig.strictNullChecks.json b/src/tsconfig.strictNullChecks.json index e4578028d55..42d5cc7389e 100644 --- a/src/tsconfig.strictNullChecks.json +++ b/src/tsconfig.strictNullChecks.json @@ -92,6 +92,7 @@ "./vs/code/electron-browser/issue/issueReporterUtil.ts", "./vs/code/electron-main/auth.ts", "./vs/code/electron-main/keyboard.ts", + "./vs/code/electron-main/sharedProcess.ts", "./vs/code/electron-main/theme.ts", "./vs/code/node/shellEnv.ts", "./vs/editor/browser/config/charWidthReader.ts", @@ -259,6 +260,7 @@ "./vs/editor/contrib/codeAction/codeActionModel.ts", "./vs/editor/contrib/codeAction/codeActionTrigger.ts", "./vs/editor/contrib/codeAction/lightBulbWidget.ts", + "./vs/editor/contrib/codelens/codelens.ts", "./vs/editor/contrib/colorPicker/color.ts", "./vs/editor/contrib/colorPicker/colorDetector.ts", "./vs/editor/contrib/colorPicker/colorPickerModel.ts", @@ -290,6 +292,7 @@ "./vs/editor/contrib/fontZoom/fontZoom.ts", "./vs/editor/contrib/goToDefinition/clickLinkGesture.ts", "./vs/editor/contrib/goToDefinition/goToDefinition.ts", + "./vs/editor/contrib/gotoError/gotoErrorWidget.ts", "./vs/editor/contrib/hover/getHover.ts", "./vs/editor/contrib/hover/hoverOperation.ts", "./vs/editor/contrib/hover/hoverWidgets.ts", @@ -335,6 +338,7 @@ "./vs/editor/test/browser/controller/imeTester.ts", "./vs/editor/test/browser/editorTestServices.ts", "./vs/editor/test/browser/testCodeEditor.ts", + "./vs/editor/test/browser/testCommand.ts", "./vs/editor/test/browser/view/minimapFontCreator.ts", "./vs/editor/test/common/commentMode.ts", "./vs/editor/test/common/core/viewLineToken.ts", @@ -503,7 +507,7 @@ "./vs/workbench/parts/codeEditor/electron-browser/toggleWordWrap.ts", "./vs/workbench/parts/comments/common/commentModel.ts", "./vs/workbench/parts/comments/electron-browser/commentGlyphWidget.ts", - "vs/workbench/parts/comments/electron-browser/commentService.ts", + "./vs/workbench/parts/comments/electron-browser/commentService.ts", "./vs/workbench/parts/emmet/browser/actions/showEmmetCommands.ts", "./vs/workbench/parts/emmet/browser/emmet.browser.contribution.ts", "./vs/workbench/parts/emmet/electron-browser/actions/expandAbbreviation.ts", @@ -537,11 +541,13 @@ "./vs/workbench/parts/surveys/electron-browser/nps.contribution.ts", "./vs/workbench/parts/tasks/common/problemCollectors.ts", "./vs/workbench/parts/tasks/common/problemMatcher.ts", + "./vs/workbench/parts/tasks/common/taskDefinitionRegistry.ts", "./vs/workbench/parts/tasks/common/taskService.ts", "./vs/workbench/parts/tasks/common/taskSystem.ts", "./vs/workbench/parts/tasks/common/taskTemplates.ts", "./vs/workbench/parts/tasks/common/tasks.ts", "./vs/workbench/parts/tasks/electron-browser/jsonSchemaCommon.ts", + "./vs/workbench/parts/tasks/node/tasks.ts", "./vs/workbench/parts/terminal/browser/terminalTab.ts", "./vs/workbench/parts/terminal/browser/terminalWidgetManager.ts", "./vs/workbench/parts/terminal/common/terminal.ts", @@ -591,6 +597,7 @@ "./vs/workbench/services/keybinding/common/macLinuxKeyboardMapper.ts", "./vs/workbench/services/keybinding/common/windowsKeyboardMapper.ts", "./vs/workbench/services/mode/common/workbenchModeService.ts", + "./vs/workbench/services/notification/common/notificationService.ts", "./vs/workbench/services/panel/common/panelService.ts", "./vs/workbench/services/part/common/partService.ts", "./vs/workbench/services/scm/common/scm.ts", diff --git a/src/vs/base/common/labels.ts b/src/vs/base/common/labels.ts index 854fbbee051..94f776bb64b 100644 --- a/src/vs/base/common/labels.ts +++ b/src/vs/base/common/labels.ts @@ -24,7 +24,7 @@ export interface IUserHomeProvider { /** * @deprecated use LabelService instead */ -export function getPathLabel(resource: URI | string, userHomeProvider: IUserHomeProvider, rootProvider?: IWorkspaceFolderProvider): string { +export function getPathLabel(resource: URI | string, userHomeProvider?: IUserHomeProvider, rootProvider?: IWorkspaceFolderProvider): string { if (typeof resource === 'string') { resource = URI.file(resource); } diff --git a/src/vs/code/electron-main/sharedProcess.ts b/src/vs/code/electron-main/sharedProcess.ts index fad75bd2d5c..b937a61d079 100644 --- a/src/vs/code/electron-main/sharedProcess.ts +++ b/src/vs/code/electron-main/sharedProcess.ts @@ -21,7 +21,7 @@ export class SharedProcess implements ISharedProcess { private barrier = new Barrier(); - private window: Electron.BrowserWindow; + private window: Electron.BrowserWindow | null; constructor( private readonly machineId: string, @@ -63,7 +63,7 @@ export class SharedProcess implements ISharedProcess { e.preventDefault(); // Still hide the window though if visible - if (this.window.isVisible()) { + if (this.window && this.window.isVisible()) { this.window.hide(); } }; @@ -81,12 +81,16 @@ export class SharedProcess implements ISharedProcess { // Otherwise the application would never quit because the shared process // window is refusing to close! // - this.window.removeListener('close', onClose); + if (this.window) { + this.window.removeListener('close', onClose); + } // Electron seems to crash on Windows without this setTimeout :| setTimeout(() => { try { - this.window.close(); + if (this.window) { + this.window.close(); + } } catch (err) { // ignore, as electron is already shutting down } @@ -118,7 +122,7 @@ export class SharedProcess implements ISharedProcess { } toggle(): void { - if (this.window.isVisible()) { + if (!this.window || this.window.isVisible()) { this.hide(); } else { this.show(); @@ -126,12 +130,16 @@ export class SharedProcess implements ISharedProcess { } show(): void { - this.window.show(); - this.window.webContents.openDevTools(); + if (this.window) { + this.window.show(); + this.window.webContents.openDevTools(); + } } hide(): void { - this.window.webContents.closeDevTools(); - this.window.hide(); + if (this.window) { + this.window.webContents.closeDevTools(); + this.window.hide(); + } } } diff --git a/src/vs/code/node/windowsFinder.ts b/src/vs/code/node/windowsFinder.ts index 02ee9c40159..16efc411041 100644 --- a/src/vs/code/node/windowsFinder.ts +++ b/src/vs/code/node/windowsFinder.ts @@ -29,7 +29,7 @@ export interface IBestWindowOrFolderOptions { workspaceResolver: (workspace: IWorkspaceIdentifier) => IResolvedWorkspace; } -export function findBestWindowOrFolderForFile({ windows, newWindow, reuseWindow, context, fileUri, workspaceResolver }: IBestWindowOrFolderOptions): W { +export function findBestWindowOrFolderForFile({ windows, newWindow, reuseWindow, context, fileUri, workspaceResolver }: IBestWindowOrFolderOptions): W | null { if (!newWindow && fileUri && (context === OpenContext.DESKTOP || context === OpenContext.CLI || context === OpenContext.DOCK)) { const windowOnFilePath = findWindowOnFilePath(windows, fileUri, workspaceResolver); if (windowOnFilePath) { @@ -39,7 +39,7 @@ export function findBestWindowOrFolderForFile({ windows return !newWindow ? getLastActiveWindow(windows) : null; } -function findWindowOnFilePath(windows: W[], fileUri: URI, workspaceResolver: (workspace: IWorkspaceIdentifier) => IResolvedWorkspace): W { +function findWindowOnFilePath(windows: W[], fileUri: URI, workspaceResolver: (workspace: IWorkspaceIdentifier) => IResolvedWorkspace): W | null { // First check for windows with workspaces that have a parent folder of the provided path opened const workspaceWindows = windows.filter(window => !!window.openedWorkspace); @@ -66,7 +66,7 @@ export function getLastActiveWindow(windows: W[]): W { return windows.filter(window => window.lastFocusTime === lastFocusedDate)[0]; } -export function findWindowOnWorkspace(windows: W[], workspace: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier)): W { +export function findWindowOnWorkspace(windows: W[], workspace: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier)): W | null { if (isSingleFolderWorkspaceIdentifier(workspace)) { for (const window of windows) { // match on folder @@ -87,7 +87,7 @@ export function findWindowOnWorkspace(windows: W[], wor return null; } -export function findWindowOnExtensionDevelopmentPath(windows: W[], extensionDevelopmentPath: string): W { +export function findWindowOnExtensionDevelopmentPath(windows: W[], extensionDevelopmentPath: string): W | null { for (const window of windows) { // match on extension development path. The path can be a path or uri string, using paths.isEqual is not 100% correct but good enough if (paths.isEqual(window.extensionDevelopmentPath, extensionDevelopmentPath, !platform.isLinux /* ignorecase */)) { @@ -97,7 +97,7 @@ export function findWindowOnExtensionDevelopmentPath(wi return null; } -export function findWindowOnWorkspaceOrFolderUri(windows: W[], uri: URI): W { +export function findWindowOnWorkspaceOrFolderUri(windows: W[], uri: URI): W | null { if (!uri) { return null; } diff --git a/src/vs/editor/contrib/codelens/codelens.ts b/src/vs/editor/contrib/codelens/codelens.ts index eecd765ece8..6dccdfd1375 100644 --- a/src/vs/editor/contrib/codelens/codelens.ts +++ b/src/vs/editor/contrib/codelens/codelens.ts @@ -73,8 +73,8 @@ registerLanguageCommand('_executeCodeLensProvider', function (accessor, args) { for (const item of value) { if (typeof itemResolveCount === 'undefined' || Boolean(item.symbol.command)) { result.push(item.symbol); - } else if (itemResolveCount-- > 0) { - resolve.push(Promise.resolve(item.provider.resolveCodeLens(model, item.symbol, CancellationToken.None)).then(symbol => result.push(symbol))); + } else if (itemResolveCount-- > 0 && item.provider.resolveCodeLens) { + resolve.push(Promise.resolve(item.provider.resolveCodeLens(model, item.symbol, CancellationToken.None)).then(symbol => result.push(symbol || item.symbol))); } } diff --git a/src/vs/editor/contrib/gotoError/gotoErrorWidget.ts b/src/vs/editor/contrib/gotoError/gotoErrorWidget.ts index 694533f44f7..72bcedbde1a 100644 --- a/src/vs/editor/contrib/gotoError/gotoErrorWidget.ts +++ b/src/vs/editor/contrib/gotoError/gotoErrorWidget.ts @@ -111,7 +111,7 @@ class MessageWidget { this._relatedBlock.style.paddingTop = `${Math.floor(this._editor.getConfiguration().lineHeight * .66)}px`; this._lines += 1; - for (const related of relatedInformation) { + for (const related of relatedInformation || []) { let container = document.createElement('div'); @@ -159,7 +159,7 @@ export class MarkerNavigationWidget extends ZoneWidget { private _message: MessageWidget; private _callOnDispose: IDisposable[] = []; private _severity: MarkerSeverity; - private _backgroundColor: Color; + private _backgroundColor: Color | null; private _onDidSelectRelatedInformation = new Emitter(); readonly onDidSelectRelatedInformation: Event = this._onDidSelectRelatedInformation.event; @@ -195,7 +195,7 @@ export class MarkerNavigationWidget extends ZoneWidget { protected _applyStyles(): void { if (this._parentContainer) { - this._parentContainer.style.backgroundColor = this._backgroundColor.toString(); + this._parentContainer.style.backgroundColor = this._backgroundColor ? this._backgroundColor.toString() : ''; } super._applyStyles(); } @@ -244,7 +244,8 @@ export class MarkerNavigationWidget extends ZoneWidget { // show let range = Range.lift(marker); - let position = range.containsPosition(this.editor.getPosition()) ? this.editor.getPosition() : range.getStartPosition(); + const editorPosition = this.editor.getPosition(); + let position = editorPosition && range.containsPosition(editorPosition) ? editorPosition : range.getStartPosition(); super.show(position, this.computeRequiredHeight()); this.editor.revealPositionInCenter(position, ScrollType.Smooth); diff --git a/src/vs/editor/contrib/zoneWidget/zoneWidget.ts b/src/vs/editor/contrib/zoneWidget/zoneWidget.ts index e2f37b85cfc..a627626bfc0 100644 --- a/src/vs/editor/contrib/zoneWidget/zoneWidget.ts +++ b/src/vs/editor/contrib/zoneWidget/zoneWidget.ts @@ -31,8 +31,8 @@ export interface IOptions { } export interface IStyles { - frameColor?: Color; - arrowColor?: Color; + frameColor?: Color | null; + arrowColor?: Color | null; } const defaultColor = new Color(new RGBA(0, 122, 204)); diff --git a/src/vs/editor/test/browser/testCommand.ts b/src/vs/editor/test/browser/testCommand.ts index c145216ddd5..7bc2f797403 100644 --- a/src/vs/editor/test/browser/testCommand.ts +++ b/src/vs/editor/test/browser/testCommand.ts @@ -61,7 +61,7 @@ export function getEditOperation(model: ITextModel, command: editorCommon.IComma trackSelection: (selection: Selection) => { - return null; + return ''; } }; command.getEditOperations(model, editOperationBuilder); diff --git a/src/vs/workbench/parts/tasks/common/taskDefinitionRegistry.ts b/src/vs/workbench/parts/tasks/common/taskDefinitionRegistry.ts index 1da2c74561f..9a6cabbb15c 100644 --- a/src/vs/workbench/parts/tasks/common/taskDefinitionRegistry.ts +++ b/src/vs/workbench/parts/tasks/common/taskDefinitionRegistry.ts @@ -46,7 +46,7 @@ namespace Configuration { properties?: IJSONSchemaMap; } - export function from(value: TaskDefinition, extensionId: string, messageCollector: ExtensionMessageCollector): Tasks.TaskDefinition { + export function from(value: TaskDefinition, extensionId: string, messageCollector: ExtensionMessageCollector): Tasks.TaskDefinition | undefined { if (!value) { return undefined; } @@ -137,7 +137,7 @@ class TaskDefinitionRegistryImpl implements ITaskDefinitionRegistry { } else { schema.properties = Object.create(null); } - schema.properties.type = { + schema.properties!.type = { type: 'string', enum: [definition.taskType] }; diff --git a/src/vs/workbench/services/notification/common/notificationService.ts b/src/vs/workbench/services/notification/common/notificationService.ts index b8eadaddd49..48e02e5db8f 100644 --- a/src/vs/workbench/services/notification/common/notificationService.ts +++ b/src/vs/workbench/services/notification/common/notificationService.ts @@ -63,8 +63,14 @@ export class NotificationService extends Disposable implements INotificationServ choices.forEach((choice, index) => { const action = new ChoiceAction(`workbench.dialog.choice.${index}`, choice); if (!choice.isSecondary) { + if (!actions.primary) { + actions.primary = []; + } actions.primary.push(action); } else { + if (!actions.secondary) { + actions.secondary = []; + } actions.secondary.push(action); } -- GitLab