Skip to content

Commit

Permalink
debt - some strict function types (#81574)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Oct 5, 2019
1 parent 875fc15 commit c617db1
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 33 deletions.
33 changes: 17 additions & 16 deletions src/vs/code/electron-main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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();
}

Expand All @@ -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),
Expand Down Expand Up @@ -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();
Expand All @@ -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();
}

Expand Down Expand Up @@ -359,7 +360,7 @@ class CodeMain {
}

private async windowsAllowSetForegroundWindow(launchService: ILaunchMainService, logService: ILogService): Promise<void> {
if (platform.isWindows) {
if (isWindows) {
const processId = await launchService.getMainProcessId();

logService.trace('Sending some foreground love to the running instance:', processId);
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/browser/labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/browser/parts/editor/editorGroupView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -420,7 +420,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
}
}

private async restoreEditors(from: IEditorGroupView | ISerializedEditorGroup): Promise<void> {
private async restoreEditors(from: IEditorGroupView | ISerializedEditorGroup | null): Promise<void> {
if (this._group.count === 0) {
return; // nothing to show
}
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/browser/parts/editor/editorPicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ 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';

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
Expand Down
6 changes: 3 additions & 3 deletions src/vs/workbench/common/editor/binaryEditorModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();
Expand All @@ -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);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/vs/workbench/common/editor/resourceEditorInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,7 +22,7 @@ export class ResourceEditorInput extends EditorInput implements IModeSupport {
private modelReference: Promise<IReference<ITextEditorModel>> | null = null;

constructor(
private name: string,
private name: string | undefined,
private description: string | undefined,
private readonly resource: URI,
private preferredMode: string | undefined,
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/common/editor/untitledEditorInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/common/editor/untitledEditorModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/files/browser/saveErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/contrib/search/browser/openFileHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -78,7 +78,7 @@ export class FileEntry extends EditorQuickOpenEntry {
return this.description;
}

getIcon(): string {
getIcon(): string | undefined {
return this.icon;
}

Expand Down

0 comments on commit c617db1

Please sign in to comment.