From c11651ee80aea2daec6fabd10ab8e25a82f8c37a Mon Sep 17 00:00:00 2001 From: David Wilson Date: Tue, 17 Jan 2017 14:50:00 -0800 Subject: [PATCH] Add setting to enable use of Windows PowerShell developer builds This change adds a new setting called "powershell.developer.powerShellExeIsWindowsDevBuild" which identifies that the specified powerShellExePath refers to a developer build of Windows PowerShell. This is needed because an environment variable needs to be set before using such a build with the PowerShell extension. --- package.json | 5 +++++ src/session.ts | 28 +++++++++++++++++++++++----- src/settings.ts | 4 +++- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index c3dcafe0f3..e792356780 100644 --- a/package.json +++ b/package.json @@ -316,6 +316,11 @@ "default": "", "description": "Specifies the full path to a PowerShell executable. Used to change the installation of PowerShell used for language and debugging services." }, + "powershell.developer.powerShellExeIsWindowsDevBuild": { + "type": "boolean", + "default": false, + "description": "If true, indicates that the powerShellExePath points to a developer build of Windows PowerShell and should be configured appropriately." + }, "powershell.developer.bundledModulesPath": { "type": "string", "default": "../modules/", diff --git a/src/session.ts b/src/session.ts index 4552954e96..64c3d6e259 100644 --- a/src/session.ts +++ b/src/session.ts @@ -42,6 +42,7 @@ interface CurrentSessionConfiguration { interface PathSessionConfiguration { type: SessionType.UsePath, path: string; + isWindowsDevBuild: boolean; } interface BuiltInSessionConfiguration { @@ -118,8 +119,13 @@ export class SessionManager { startArgs += "-LogLevel '" + this.sessionSettings.developer.editorServicesLogLevel + "' " } + var isWindowsDevBuild = + this.sessionConfiguration.type == SessionType.UsePath + ? this.sessionConfiguration.isWindowsDevBuild : false; + this.startPowerShell( this.sessionConfiguration.path, + isWindowsDevBuild, bundledModulesPath, startArgs); } @@ -214,7 +220,11 @@ export class SessionManager { ] } - private startPowerShell(powerShellExePath: string, bundledModulesPath: string, startArgs: string) { + private startPowerShell( + powerShellExePath: string, + isWindowsDevBuild: boolean, + bundledModulesPath: string, + startArgs: string) { try { this.setSessionStatus( @@ -242,10 +252,14 @@ export class SessionManager { powerShellArgs.push( "-Command", - "& '" + startScriptPath + "' " + startArgs) + "& '" + startScriptPath + "' " + startArgs); // Launch PowerShell as child process - this.powerShellProcess = cp.spawn(powerShellExePath, powerShellArgs); + this.powerShellProcess = + cp.spawn( + powerShellExePath, + powerShellArgs, + { env: isWindowsDevBuild ? { "DEVPATH": path.dirname(powerShellExePath) } : {} }); var decoder = new StringDecoder('utf8'); this.powerShellProcess.stdout.on( @@ -466,7 +480,9 @@ export class SessionManager { var powerShellExePath = (this.sessionSettings.developer.powerShellExePath || "").trim(); if (powerShellExePath.length > 0) { return this.resolveSessionConfiguration( - { type: SessionType.UsePath, path: this.sessionSettings.developer.powerShellExePath}); + { type: SessionType.UsePath, + path: this.sessionSettings.developer.powerShellExePath, + isWindowsDevBuild: this.sessionSettings.developer.powerShellExeIsWindowsDevBuild}); } else { return this.resolveSessionConfiguration( @@ -591,7 +607,9 @@ export class SessionManager { `Switch to PowerShell at path: ${this.sessionSettings.developer.powerShellExePath}`, () => { this.restartSession( - { type: SessionType.UsePath, path: this.sessionSettings.developer.powerShellExePath }) + { type: SessionType.UsePath, + path: this.sessionSettings.developer.powerShellExePath, + isWindowsDevBuild: this.sessionSettings.developer.powerShellExeIsWindowsDevBuild }) })); } diff --git a/src/settings.ts b/src/settings.ts index b29237ef40..5bf3159d8d 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -21,6 +21,7 @@ export interface IDeveloperSettings { bundledModulesPath?: string; editorServicesLogLevel?: string; editorServicesWaitForDebugger?: boolean; + powerShellExeIsWindowsDevBuild?: boolean; } export interface ISettings { @@ -43,7 +44,8 @@ export function load(myPluginId: string): ISettings { powerShellExePath: undefined, bundledModulesPath: "../modules/", editorServicesLogLevel: "Normal", - editorServicesWaitForDebugger: false + editorServicesWaitForDebugger: false, + powerShellExeIsWindowsDevBuild: false }; let defaultCodeFormattingSettings: ICodeFormattingSettings = {