From 89a234b9f00aca9cf9b174354b9b5c9041cc8dcc Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Wed, 17 Aug 2016 14:36:25 +0200 Subject: [PATCH] more env passing --- .../environment/common/environment.ts | 1 + .../environment/node/environmentService.ts | 1 + src/vs/workbench/node/extensionHostMain.ts | 27 ++++++++++++------- .../thread/electron-browser/threadService.ts | 7 +++++ 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/vs/platform/environment/common/environment.ts b/src/vs/platform/environment/common/environment.ts index 65793b191bc..2b5c82709cc 100644 --- a/src/vs/platform/environment/common/environment.ts +++ b/src/vs/platform/environment/common/environment.ts @@ -20,6 +20,7 @@ export interface IEnvironmentService { appSettingsPath: string; appKeybindingsPath: string; + disableExtensions: boolean; extensionsPath: string; extensionDevelopmentPath: string; extensionTestsPath: string; diff --git a/src/vs/platform/environment/node/environmentService.ts b/src/vs/platform/environment/node/environmentService.ts index 9fa1c69f6fa..21f61ced9b3 100644 --- a/src/vs/platform/environment/node/environmentService.ts +++ b/src/vs/platform/environment/node/environmentService.ts @@ -48,6 +48,7 @@ export class EnvironmentService implements IEnvironmentService { get extensionDevelopmentPath(): string { return this._extensionDevelopmentPath; } get extensionTestsPath(): string { return this.args.extensionTestsPath; } + get disableExtensions(): boolean { return this.args['disable-extensions']; } private _debugExtensionHostPort: number; get debugExtensionHostPort(): number { return this._debugExtensionHostPort; } diff --git a/src/vs/workbench/node/extensionHostMain.ts b/src/vs/workbench/node/extensionHostMain.ts index 23515548c66..86fb6539cfa 100644 --- a/src/vs/workbench/node/extensionHostMain.ts +++ b/src/vs/workbench/node/extensionHostMain.ts @@ -31,7 +31,16 @@ const DIRNAME = URI.parse(require.toUrl('./')).fsPath; const BASE_PATH = paths.normalize(paths.join(DIRNAME, '../../../..')); const BUILTIN_EXTENSIONS_PATH = paths.join(BASE_PATH, 'extensions'); +export interface IEnvironment { + appSettingsHome: string; + disableExtensions: boolean; + userExtensionsHome: string; + extensionDevelopmentPath: string; + extensionTestsPath: string; +} + export interface IInitData { + environment: IEnvironment; threadService: any; contextService: { workspace: any; @@ -57,11 +66,14 @@ export class ExtensionHostMain { private _isTerminating: boolean; private _contextService: IWorkspaceContextService; + private _environment: IEnvironment; private _extensionService: ExtHostExtensionService; constructor(remoteCom: IMainProcessExtHostIPC, initData: IInitData, sharedProcessClient: Client) { this._isTerminating = false; + this._environment = initData.environment; + this._contextService = new BaseWorkspaceContextService(initData.contextService.workspace, initData.contextService.configuration, initData.contextService.options); const workspaceStoragePath = this._getOrCreateWorkspaceStoragePath(); @@ -87,7 +99,6 @@ export class ExtensionHostMain { let workspaceStoragePath: string; const workspace = this._contextService.getWorkspace(); - const env = this._contextService.getConfiguration().env; function rmkDir(directory: string): boolean { try { @@ -111,7 +122,7 @@ export class ExtensionHostMain { if (workspace.uid) { hash.update(workspace.uid.toString()); } - workspaceStoragePath = paths.join(env.appSettingsHome, 'workspaceStorage', hash.digest('hex')); + workspaceStoragePath = paths.join(this._environment.appSettingsHome, 'workspaceStorage', hash.digest('hex')); if (!fs.existsSync(workspaceStoragePath)) { try { if (rmkDir(workspaceStoragePath)) { @@ -162,9 +173,8 @@ export class ExtensionHostMain { private readExtensions(): TPromise { let collector = new MessagesCollector(); - let env = this._contextService.getConfiguration().env; - return ExtensionHostMain.scanExtensions(collector, BUILTIN_EXTENSIONS_PATH, !env.disableExtensions ? env.userExtensionsHome : void 0, !env.disableExtensions ? env.extensionDevelopmentPath : void 0, pkg.version) + return ExtensionHostMain.scanExtensions(collector, BUILTIN_EXTENSIONS_PATH, !this._environment.disableExtensions ? this._environment.userExtensionsHome : void 0, !this._environment.disableExtensions ? this._environment.extensionDevelopmentPath : void 0, pkg.version) .then(null, err => { collector.error('', err); return []; @@ -263,8 +273,7 @@ export class ExtensionHostMain { } private handleExtensionTests(): TPromise { - let env = this._contextService.getConfiguration().env; - if (!env.extensionTestsPath || !env.extensionDevelopmentPath) { + if (!this._environment.extensionTestsPath || !this._environment.extensionDevelopmentPath) { return TPromise.as(null); } @@ -272,7 +281,7 @@ export class ExtensionHostMain { let testRunner: ITestRunner; let requireError: Error; try { - testRunner = require.__$__nodeRequire(env.extensionTestsPath); + testRunner = require.__$__nodeRequire(this._environment.extensionTestsPath); } catch (error) { requireError = error; } @@ -280,7 +289,7 @@ export class ExtensionHostMain { // Execute the runner if it follows our spec if (testRunner && typeof testRunner.run === 'function') { return new TPromise((c, e) => { - testRunner.run(env.extensionTestsPath, (error, failures) => { + testRunner.run(this._environment.extensionTestsPath, (error, failures) => { if (error) { e(error.toString()); } else { @@ -298,7 +307,7 @@ export class ExtensionHostMain { this.gracefulExit(1 /* ERROR */); } - return TPromise.wrapError(requireError ? requireError.toString() : nls.localize('extensionTestError', "Path {0} does not point to a valid extension test runner.", env.extensionTestsPath)); + return TPromise.wrapError(requireError ? requireError.toString() : nls.localize('extensionTestError', "Path {0} does not point to a valid extension test runner.", this._environment.extensionTestsPath)); } private gracefulExit(code: number): void { diff --git a/src/vs/workbench/services/thread/electron-browser/threadService.ts b/src/vs/workbench/services/thread/electron-browser/threadService.ts index 81f2352bec5..a3d9c0cc14d 100644 --- a/src/vs/workbench/services/thread/electron-browser/threadService.ts +++ b/src/vs/workbench/services/thread/electron-browser/threadService.ts @@ -168,6 +168,13 @@ class ExtensionHostProcessManager { let initPayload = stringify({ parentPid: process.pid, + environment: { + appSettingsHome: this.environmentService.appSettingsHome, + disableExtensions: this.environmentService.disableExtensions, + userExtensionsHome: this.environmentService.extensionsPath, + extensionDevelopmentPath: this.environmentService.extensionDevelopmentPath, + extensionTestsPath: this.environmentService.extensionTestsPath + }, contextService: { workspace: this.contextService.getWorkspace(), configuration: this.contextService.getConfiguration(),