From bb25b46ff42d17f22c89ddbef1636617d31ae53c Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Fri, 19 Aug 2016 15:48:38 +0200 Subject: [PATCH] decouple execPath from parsedArgs --- src/vs/code/electron-main/main.ts | 2 +- src/vs/code/node/cliProcessMain.ts | 3 +-- src/vs/code/node/sharedProcessMain.ts | 3 +-- .../platform/environment/node/environmentService.ts | 11 +++-------- src/vs/test/utils/servicesTestUtils.ts | 3 +-- src/vs/workbench/electron-browser/main.ts | 9 +++++---- 6 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/vs/code/electron-main/main.ts b/src/vs/code/electron-main/main.ts index 0ed34dea755..3b7c95711ae 100644 --- a/src/vs/code/electron-main/main.ts +++ b/src/vs/code/electron-main/main.ts @@ -273,7 +273,7 @@ function setupIPC(accessor: ServicesAccessor): TPromise { const services = new ServiceCollection(); services.set(IEnvService, new SyncDescriptor(EnvService)); -services.set(IEnvironmentService, new SyncDescriptor(EnvironmentService, parseArgs(process.argv))); +services.set(IEnvironmentService, new SyncDescriptor(EnvironmentService, parseArgs(process.argv), process.execPath)); services.set(ILogService, new SyncDescriptor(MainLogService)); services.set(IWindowsService, new SyncDescriptor(WindowsManager)); services.set(ILifecycleService, new SyncDescriptor(LifecycleService)); diff --git a/src/vs/code/node/cliProcessMain.ts b/src/vs/code/node/cliProcessMain.ts index 7a88e3c8480..cc3acb5bc2a 100644 --- a/src/vs/code/node/cliProcessMain.ts +++ b/src/vs/code/node/cliProcessMain.ts @@ -10,7 +10,6 @@ import * as path from 'path'; import { parseArgs, ParsedArgs } from 'vs/code/node/argv'; import { TPromise } from 'vs/base/common/winjs.base'; import { sequence } from 'vs/base/common/async'; -import * as objects from 'vs/base/common/objects'; import { IPager } from 'vs/base/common/paging'; import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; @@ -146,7 +145,7 @@ const eventPrefix = 'monacoworkbench'; export function main(argv: ParsedArgs): TPromise { const services = new ServiceCollection(); - services.set(IEnvironmentService, new SyncDescriptor(EnvironmentService, objects.assign(parseArgs(process.argv), { execPath: process.execPath }))); + services.set(IEnvironmentService, new SyncDescriptor(EnvironmentService, parseArgs(process.argv), process.execPath)); const instantiationService: IInstantiationService = new InstantiationService(services); diff --git a/src/vs/code/node/sharedProcessMain.ts b/src/vs/code/node/sharedProcessMain.ts index e1f9e6c6950..0fa48cac03c 100644 --- a/src/vs/code/node/sharedProcessMain.ts +++ b/src/vs/code/node/sharedProcessMain.ts @@ -6,7 +6,6 @@ import * as fs from 'fs'; import * as platform from 'vs/base/common/platform'; import product from 'vs/platform/product'; -import * as objects from 'vs/base/common/objects'; import pkg from 'vs/platform/package'; import { serve, Server, connect } from 'vs/base/parts/ipc/node/ipc.net'; import { TPromise } from 'vs/base/common/winjs.base'; @@ -59,7 +58,7 @@ function main(server: Server): void { const services = new ServiceCollection(); services.set(IEventService, new SyncDescriptor(EventService)); - services.set(IEnvironmentService, new SyncDescriptor(EnvironmentService, objects.assign(parseArgs(process.argv), { execPath: process.execPath }))); + services.set(IEnvironmentService, new SyncDescriptor(EnvironmentService, parseArgs(process.argv), process.execPath)); services.set(IConfigurationService, new SyncDescriptor(NodeConfigurationService)); services.set(IRequestService, new SyncDescriptor(RequestService)); diff --git a/src/vs/platform/environment/node/environmentService.ts b/src/vs/platform/environment/node/environmentService.ts index 294db648604..9b07d29edcd 100644 --- a/src/vs/platform/environment/node/environmentService.ts +++ b/src/vs/platform/environment/node/environmentService.ts @@ -14,12 +14,6 @@ import { memoize } from 'vs/base/common/decorators'; import pkg from 'vs/platform/package'; import product from 'vs/platform/product'; -// TODO@Ben TODO@Joao this interface should be composed once the main => renderer -// communication is also fit for that -export interface IEnvironment extends ParsedArgs { - execPath: string; -} - function getUniqueUserId(): string { let username: string; if (process.platform === 'win32') { @@ -62,7 +56,8 @@ export class EnvironmentService implements IEnvironmentService { @memoize get appRoot(): string { return path.dirname(URI.parse(require.toUrl('')).fsPath); } - get execPath(): string { return this.args.execPath; } + + get execPath(): string { return this._execPath; } @memoize get userHome(): string { return path.join(os.homedir(), product.dataFolderName); } @@ -101,7 +96,7 @@ export class EnvironmentService implements IEnvironmentService { @memoize get sharedIPCHandle(): string { return `${ IPCHandlePrefix }-${ pkg.version }-shared${ IPCHandleSuffix }`; } - constructor(private args: IEnvironment) {} + constructor(private args: ParsedArgs, private _execPath: string) {} } export function parseExtensionHostPort(args: ParsedArgs, isBuild: boolean): { port: number; break: boolean; } { diff --git a/src/vs/test/utils/servicesTestUtils.ts b/src/vs/test/utils/servicesTestUtils.ts index 03d5974274f..bc488073732 100644 --- a/src/vs/test/utils/servicesTestUtils.ts +++ b/src/vs/test/utils/servicesTestUtils.ts @@ -14,7 +14,6 @@ import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry'; import Storage = require('vs/workbench/common/storage'); import {EditorInputEvent, IEditorGroup} from 'vs/workbench/common/editor'; import Event, {Emitter} from 'vs/base/common/event'; -import Objects = require('vs/base/common/objects'); import Severity from 'vs/base/common/severity'; import {IConfigurationService} from 'vs/platform/configuration/common/configuration'; import {IContent, IStat} from 'vs/platform/configuration/common/configurationService'; @@ -49,7 +48,7 @@ export const TestWorkspace: IWorkspace = { uid: new Date().getTime() }; -export const TestEnvironmentService = new EnvironmentService(Objects.assign(parseArgs(process.argv), { execPath: process.execPath })); +export const TestEnvironmentService = new EnvironmentService(parseArgs(process.argv), process.execPath); export class TestContextService implements WorkspaceContextService.IWorkspaceContextService { public _serviceBrand: any; diff --git a/src/vs/workbench/electron-browser/main.ts b/src/vs/workbench/electron-browser/main.ts index 8ed5abafcd5..94a06321b7f 100644 --- a/src/vs/workbench/electron-browser/main.ts +++ b/src/vs/workbench/electron-browser/main.ts @@ -20,7 +20,8 @@ import {LegacyWorkspaceContextService} from 'vs/workbench/services/workspace/com import {IWorkspace} from 'vs/platform/workspace/common/workspace'; import {ConfigurationService} from 'vs/workbench/services/configuration/node/configurationService'; import {IProcessEnvironment} from 'vs/code/electron-main/env'; -import {EnvironmentService, IEnvironment} from 'vs/platform/environment/node/environmentService'; +import {ParsedArgs} from 'vs/code/node/argv'; +import {EnvironmentService} from 'vs/platform/environment/node/environmentService'; import path = require('path'); import fs = require('fs'); import gracefulFs = require('graceful-fs'); @@ -46,7 +47,7 @@ export interface IPath { columnNumber?: number; } -export interface IWindowConfiguration extends IEnvironment { +export interface IWindowConfiguration extends ParsedArgs { appRoot: string; execPath: string; @@ -127,9 +128,9 @@ function getWorkspace(workspacePath: string): IWorkspace { }; } -function openWorkbench(environment: IEnvironment, workspace: IWorkspace, options: IOptions): winjs.TPromise { +function openWorkbench(environment: IWindowConfiguration, workspace: IWorkspace, options: IOptions): winjs.TPromise { const eventService = new EventService(); - const environmentService = new EnvironmentService(environment); + const environmentService = new EnvironmentService(environment, environment.execPath); const contextService = new LegacyWorkspaceContextService(eventService, workspace, options); const configurationService = new ConfigurationService(contextService, eventService, environmentService); -- GitLab