From c617db19b08bfdae8e2c540470bf82dd405c3895 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Sat, 5 Oct 2019 16:11:41 +0200 Subject: [PATCH] debt - some strict function types (#81574) --- src/vs/code/electron-main/main.ts | 33 ++++++++++--------- src/vs/workbench/browser/labels.ts | 4 +-- .../parts/activitybar/activitybarPart.ts | 2 +- .../browser/parts/editor/editorGroupView.ts | 4 +-- .../browser/parts/editor/editorPicker.ts | 4 +-- .../common/editor/binaryEditorModel.ts | 6 ++-- .../common/editor/resourceEditorInput.ts | 5 +-- .../common/editor/untitledEditorInput.ts | 2 +- .../common/editor/untitledEditorModel.ts | 2 +- .../contrib/files/browser/saveErrorHandler.ts | 2 +- .../contrib/search/browser/openFileHandler.ts | 4 +-- 11 files changed, 35 insertions(+), 33 deletions(-) diff --git a/src/vs/code/electron-main/main.ts b/src/vs/code/electron-main/main.ts index 65fb5ec946c8c..9a4f97020eb94 100644 --- a/src/vs/code/electron-main/main.ts +++ b/src/vs/code/electron-main/main.ts @@ -6,7 +6,7 @@ import 'vs/platform/update/common/update.config.contribution'; import { app, dialog } from 'electron'; import { assign } from 'vs/base/common/objects'; -import * as platform from 'vs/base/common/platform'; +import { isWindows, IProcessEnvironment, isMacintosh } from 'vs/base/common/platform'; import product from 'vs/platform/product/common/product'; import { parseMainProcessArgv } from 'vs/platform/environment/node/argvHelper'; import { addArg, createWaitMarkerFile } from 'vs/platform/environment/node/argv'; @@ -132,7 +132,7 @@ class CodeMain { } } - private createServices(args: ParsedArgs, bufferLogService: BufferLogService): [IInstantiationService, typeof process.env] { + private createServices(args: ParsedArgs, bufferLogService: BufferLogService): [IInstantiationService, IProcessEnvironment] { const services = new ServiceCollection(); const environmentService = new EnvironmentService(args, process.execPath); @@ -174,16 +174,17 @@ class CodeMain { return Promise.all([environmentServiceInitialization, configurationServiceInitialization, stateServiceInitialization]); } - private patchEnvironment(environmentService: IEnvironmentService): typeof process.env { - const instanceEnvironment: typeof process.env = { - VSCODE_IPC_HOOK: environmentService.mainIPCHandle, - VSCODE_NLS_CONFIG: process.env['VSCODE_NLS_CONFIG'], - VSCODE_LOGS: process.env['VSCODE_LOGS'] + private patchEnvironment(environmentService: IEnvironmentService): IProcessEnvironment { + const instanceEnvironment: IProcessEnvironment = { + VSCODE_IPC_HOOK: environmentService.mainIPCHandle }; - if (process.env['VSCODE_PORTABLE']) { - instanceEnvironment['VSCODE_PORTABLE'] = process.env['VSCODE_PORTABLE']; - } + ['VSCODE_NLS_CONFIG', 'VSCODE_LOGS', 'VSCODE_PORTABLE'].forEach(key => { + const value = process.env[key]; + if (typeof value === 'string') { + instanceEnvironment[key] = value; + } + }); assign(process.env, instanceEnvironment); @@ -213,7 +214,7 @@ class CodeMain { } // Since we are the second instance, we do not want to show the dock - if (platform.isMacintosh) { + if (isMacintosh) { app.dock.hide(); } @@ -224,7 +225,7 @@ class CodeMain { } catch (error) { // Handle unexpected connection errors by showing a dialog to the user - if (!retry || platform.isWindows || error.code !== 'ECONNREFUSED') { + if (!retry || isWindows || error.code !== 'ECONNREFUSED') { if (error.code === 'EPERM') { this.showStartupWarningDialog( localize('secondInstanceAdmin', "A second instance of {0} is already running as administrator.", product.nameShort), @@ -290,13 +291,13 @@ class CodeMain { } // Windows: allow to set foreground - if (platform.isWindows) { + if (isWindows) { await this.windowsAllowSetForegroundWindow(launchService, logService); } // Send environment over... logService.trace('Sending env to running instance...'); - await launchService.start(environmentService.args, process.env as platform.IProcessEnvironment); + await launchService.start(environmentService.args, process.env as IProcessEnvironment); // Cleanup client.dispose(); @@ -317,7 +318,7 @@ class CodeMain { } // dock might be hidden at this case due to a retry - if (platform.isMacintosh) { + if (isMacintosh) { app.dock.show(); } @@ -359,7 +360,7 @@ class CodeMain { } private async windowsAllowSetForegroundWindow(launchService: ILaunchMainService, logService: ILogService): Promise { - if (platform.isWindows) { + if (isWindows) { const processId = await launchService.getMainProcessId(); logService.trace('Sending some foreground love to the running instance:', processId); diff --git a/src/vs/workbench/browser/labels.ts b/src/vs/workbench/browser/labels.ts index 2b5d9be879046..d9e9d143bed86 100644 --- a/src/vs/workbench/browser/labels.ts +++ b/src/vs/workbench/browser/labels.ts @@ -211,7 +211,7 @@ export class ResourceLabel extends ResourceLabels { constructor( container: HTMLElement, - options: IIconLabelCreationOptions, + options: IIconLabelCreationOptions | undefined, @IInstantiationService instantiationService: IInstantiationService, @IExtensionService extensionService: IExtensionService, @IConfigurationService configurationService: IConfigurationService, @@ -252,7 +252,7 @@ class ResourceLabelWidget extends IconLabel { constructor( container: HTMLElement, - options: IIconLabelCreationOptions, + options: IIconLabelCreationOptions | undefined, @IModeService private readonly modeService: IModeService, @IModelService private readonly modelService: IModelService, @IDecorationsService private readonly decorationsService: IDecorationsService, diff --git a/src/vs/workbench/browser/parts/activitybar/activitybarPart.ts b/src/vs/workbench/browser/parts/activitybar/activitybarPart.ts index e98dc75359770..14848f29ec12e 100644 --- a/src/vs/workbench/browser/parts/activitybar/activitybarPart.ts +++ b/src/vs/workbench/browser/parts/activitybar/activitybarPart.ts @@ -280,7 +280,7 @@ export class ActivitybarPart extends Part implements IActivityBarService { private createGlobalActivityActionBar(container: HTMLElement): void { this.globalActivityActionBar = this._register(new ActionBar(container, { - actionViewItemProvider: a => this.instantiationService.createInstance(GlobalActivityActionViewItem, a, (theme: ITheme) => this.getActivitybarItemColors(theme)), + actionViewItemProvider: action => this.instantiationService.createInstance(GlobalActivityActionViewItem, action, (theme: ITheme) => this.getActivitybarItemColors(theme)), orientation: ActionsOrientation.VERTICAL, ariaLabel: nls.localize('manage', "Manage"), animated: false diff --git a/src/vs/workbench/browser/parts/editor/editorGroupView.ts b/src/vs/workbench/browser/parts/editor/editorGroupView.ts index 72708e0a4b9c4..8f4e19ed0226a 100644 --- a/src/vs/workbench/browser/parts/editor/editorGroupView.ts +++ b/src/vs/workbench/browser/parts/editor/editorGroupView.ts @@ -119,7 +119,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView { constructor( private accessor: IEditorGroupsAccessor, - from: IEditorGroupView | ISerializedEditorGroup, + from: IEditorGroupView | ISerializedEditorGroup | null, private _index: number, @IInstantiationService private readonly instantiationService: IInstantiationService, @IContextKeyService private readonly contextKeyService: IContextKeyService, @@ -420,7 +420,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView { } } - private async restoreEditors(from: IEditorGroupView | ISerializedEditorGroup): Promise { + private async restoreEditors(from: IEditorGroupView | ISerializedEditorGroup | null): Promise { if (this._group.count === 0) { return; // nothing to show } diff --git a/src/vs/workbench/browser/parts/editor/editorPicker.ts b/src/vs/workbench/browser/parts/editor/editorPicker.ts index a3d495473f501..1c8e7996d068e 100644 --- a/src/vs/workbench/browser/parts/editor/editorPicker.ts +++ b/src/vs/workbench/browser/parts/editor/editorPicker.ts @@ -15,7 +15,7 @@ import { QuickOpenHandler } from 'vs/workbench/browser/quickopen'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IEditorGroupsService, IEditorGroup, EditorsOrder, GroupsOrder } from 'vs/workbench/services/editor/common/editorGroupsService'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; -import { EditorInput, toResource, SideBySideEditor } from 'vs/workbench/common/editor'; +import { toResource, SideBySideEditor, IEditorInput } from 'vs/workbench/common/editor'; import { compareItemsByScore, scoreItem, ScorerCache, prepareQuery } from 'vs/base/parts/quickopen/common/quickOpenScorer'; import { CancellationToken } from 'vs/base/common/cancellation'; import { withNullAsUndefined } from 'vs/base/common/types'; @@ -23,7 +23,7 @@ import { withNullAsUndefined } from 'vs/base/common/types'; export class EditorPickerEntry extends QuickOpenEntryGroup { constructor( - private editor: EditorInput, + private editor: IEditorInput, private _group: IEditorGroup, @IModeService private readonly modeService: IModeService, @IModelService private readonly modelService: IModelService diff --git a/src/vs/workbench/common/editor/binaryEditorModel.ts b/src/vs/workbench/common/editor/binaryEditorModel.ts index 48c1cf5582c7a..dc631e33a8875 100644 --- a/src/vs/workbench/common/editor/binaryEditorModel.ts +++ b/src/vs/workbench/common/editor/binaryEditorModel.ts @@ -7,7 +7,7 @@ import { EditorModel } from 'vs/workbench/common/editor'; import { URI } from 'vs/base/common/uri'; import { IFileService } from 'vs/platform/files/common/files'; import { Schemas } from 'vs/base/common/network'; -import { DataUri } from 'vs/base/common/resources'; +import { DataUri, basename } from 'vs/base/common/resources'; /** * An editor model that just represents a resource that can be loaded. @@ -19,7 +19,7 @@ export class BinaryEditorModel extends EditorModel { constructor( private readonly resource: URI, - private readonly name: string, + private readonly name: string | undefined, @IFileService private readonly fileService: IFileService ) { super(); @@ -41,7 +41,7 @@ export class BinaryEditorModel extends EditorModel { * The name of the binary resource. */ getName(): string { - return this.name; + return this.name || basename(this.resource); } /** diff --git a/src/vs/workbench/common/editor/resourceEditorInput.ts b/src/vs/workbench/common/editor/resourceEditorInput.ts index 1d7712d1c4e90..ee9605889c4cd 100644 --- a/src/vs/workbench/common/editor/resourceEditorInput.ts +++ b/src/vs/workbench/common/editor/resourceEditorInput.ts @@ -8,6 +8,7 @@ import { URI } from 'vs/base/common/uri'; import { IReference } from 'vs/base/common/lifecycle'; import { ITextModelService } from 'vs/editor/common/services/resolverService'; import { ResourceEditorModel } from 'vs/workbench/common/editor/resourceEditorModel'; +import { basename } from 'vs/base/common/resources'; /** * A read-only text editor input whos contents are made of the provided resource that points to an existing @@ -21,7 +22,7 @@ export class ResourceEditorInput extends EditorInput implements IModeSupport { private modelReference: Promise> | null = null; constructor( - private name: string, + private name: string | undefined, private description: string | undefined, private readonly resource: URI, private preferredMode: string | undefined, @@ -43,7 +44,7 @@ export class ResourceEditorInput extends EditorInput implements IModeSupport { } getName(): string { - return this.name; + return this.name || basename(this.resource); } setName(name: string): void { diff --git a/src/vs/workbench/common/editor/untitledEditorInput.ts b/src/vs/workbench/common/editor/untitledEditorInput.ts index f9f8962e62dd5..a446559f1ed59 100644 --- a/src/vs/workbench/common/editor/untitledEditorInput.ts +++ b/src/vs/workbench/common/editor/untitledEditorInput.ts @@ -35,7 +35,7 @@ export class UntitledEditorInput extends EditorInput implements IEncodingSupport constructor( private readonly resource: URI, private readonly _hasAssociatedFilePath: boolean, - private preferredMode: string, + private preferredMode: string | undefined, private readonly initialValue: string | undefined, private preferredEncoding: string | undefined, @IInstantiationService private readonly instantiationService: IInstantiationService, diff --git a/src/vs/workbench/common/editor/untitledEditorModel.ts b/src/vs/workbench/common/editor/untitledEditorModel.ts index cc60963899630..152eea5f3868f 100644 --- a/src/vs/workbench/common/editor/untitledEditorModel.ts +++ b/src/vs/workbench/common/editor/untitledEditorModel.ts @@ -36,7 +36,7 @@ export class UntitledEditorModel extends BaseTextEditorModel implements IEncodin private configuredEncoding?: string; constructor( - private readonly preferredMode: string, + private readonly preferredMode: string | undefined, private readonly resource: URI, private _hasAssociatedFilePath: boolean, private readonly initialValue: string | undefined, diff --git a/src/vs/workbench/contrib/files/browser/saveErrorHandler.ts b/src/vs/workbench/contrib/files/browser/saveErrorHandler.ts index 608638b517820..fb12ef07f8905 100644 --- a/src/vs/workbench/contrib/files/browser/saveErrorHandler.ts +++ b/src/vs/workbench/contrib/files/browser/saveErrorHandler.ts @@ -141,7 +141,7 @@ export class SaveErrorHandler extends Disposable implements ISaveErrorHandler, I // Save Elevated if (canHandlePermissionOrReadonlyErrors && (isPermissionDenied || triedToMakeWriteable)) { - primaryActions.push(this.instantiationService.createInstance(SaveElevatedAction, model, triedToMakeWriteable)); + primaryActions.push(this.instantiationService.createInstance(SaveElevatedAction, model, !!triedToMakeWriteable)); } // Overwrite diff --git a/src/vs/workbench/contrib/search/browser/openFileHandler.ts b/src/vs/workbench/contrib/search/browser/openFileHandler.ts index 0374b69749f61..c2ecf87666429 100644 --- a/src/vs/workbench/contrib/search/browser/openFileHandler.ts +++ b/src/vs/workbench/contrib/search/browser/openFileHandler.ts @@ -50,7 +50,7 @@ export class FileEntry extends EditorQuickOpenEntry { private resource: URI, private name: string, private description: string, - private icon: string, + private icon: string | undefined, @IEditorService editorService: IEditorService, @IModeService private readonly modeService: IModeService, @IModelService private readonly modelService: IModelService, @@ -78,7 +78,7 @@ export class FileEntry extends EditorQuickOpenEntry { return this.description; } - getIcon(): string { + getIcon(): string | undefined { return this.icon; }