提交 8df9f241 编写于 作者: M Matt Bierner

Strict null checks

上级 21816902
......@@ -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",
......
......@@ -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);
}
......
......@@ -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();
}
}
}
......@@ -29,7 +29,7 @@ export interface IBestWindowOrFolderOptions<W extends ISimpleWindow> {
workspaceResolver: (workspace: IWorkspaceIdentifier) => IResolvedWorkspace;
}
export function findBestWindowOrFolderForFile<W extends ISimpleWindow>({ windows, newWindow, reuseWindow, context, fileUri, workspaceResolver }: IBestWindowOrFolderOptions<W>): W {
export function findBestWindowOrFolderForFile<W extends ISimpleWindow>({ windows, newWindow, reuseWindow, context, fileUri, workspaceResolver }: IBestWindowOrFolderOptions<W>): 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<W extends ISimpleWindow>({ windows
return !newWindow ? getLastActiveWindow(windows) : null;
}
function findWindowOnFilePath<W extends ISimpleWindow>(windows: W[], fileUri: URI, workspaceResolver: (workspace: IWorkspaceIdentifier) => IResolvedWorkspace): W {
function findWindowOnFilePath<W extends ISimpleWindow>(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<W extends ISimpleWindow>(windows: W[]): W {
return windows.filter(window => window.lastFocusTime === lastFocusedDate)[0];
}
export function findWindowOnWorkspace<W extends ISimpleWindow>(windows: W[], workspace: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier)): W {
export function findWindowOnWorkspace<W extends ISimpleWindow>(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<W extends ISimpleWindow>(windows: W[], wor
return null;
}
export function findWindowOnExtensionDevelopmentPath<W extends ISimpleWindow>(windows: W[], extensionDevelopmentPath: string): W {
export function findWindowOnExtensionDevelopmentPath<W extends ISimpleWindow>(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<W extends ISimpleWindow>(wi
return null;
}
export function findWindowOnWorkspaceOrFolderUri<W extends ISimpleWindow>(windows: W[], uri: URI): W {
export function findWindowOnWorkspaceOrFolderUri<W extends ISimpleWindow>(windows: W[], uri: URI): W | null {
if (!uri) {
return null;
}
......
......@@ -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)));
}
}
......
......@@ -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<IRelatedInformation>();
readonly onDidSelectRelatedInformation: Event<IRelatedInformation> = 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);
......
......@@ -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));
......
......@@ -61,7 +61,7 @@ export function getEditOperation(model: ITextModel, command: editorCommon.IComma
trackSelection: (selection: Selection) => {
return null;
return '';
}
};
command.getEditOperations(model, editOperationBuilder);
......
......@@ -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]
};
......
......@@ -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);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册