Skip to content

Commit 0866b10

Browse files
committed
Don't send empty environment vars when not Windows PowerShell dev build
This change fixes an issue where $env:PROCESSOR_ARCHITECTURE is not being set properly in the language server's powershell.exe process which caused an exception when gathering that variable. The problem was caused by the environment variable setting behavior when the Windows PowerShell developer build setting is set to false. In this case, an empty environment variable object was being passed to the process, effectively clearing its environment variables. This is one half of the fix to PowerShell/PowerShellEditorServices#346.
1 parent 790e316 commit 0866b10

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/session.ts

+17-4
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,23 @@ export class SessionManager {
254254
"-Command",
255255
"& '" + startScriptPath + "' " + startArgs);
256256

257+
// Set DEVPATH environment variable if necessary
258+
if (isWindowsDevBuild) {
259+
// The development build looks for this environment variable to
260+
// know where to find its assemblies
261+
process.env.DEVPATH = path.dirname(powerShellExePath);
262+
}
263+
else {
264+
// It's safe to delete this variable even if it doesn't exist
265+
delete process.env.DEVPATH;
266+
}
267+
257268
// Launch PowerShell as child process
258269
this.powerShellProcess =
259270
cp.spawn(
260271
powerShellExePath,
261272
powerShellArgs,
262-
{ env: isWindowsDevBuild ? { "DEVPATH": path.dirname(powerShellExePath) } : {} });
273+
{ env: process.env });
263274

264275
var decoder = new StringDecoder('utf8');
265276
this.powerShellProcess.stdout.on(
@@ -545,15 +556,17 @@ export class SessionManager {
545556
}
546557

547558
private resolvePowerShellPath(powerShellExePath: string): string {
559+
var resolvedPath = path.resolve(__dirname, powerShellExePath);
560+
548561
// If the path does not exist, show an error
549-
if (!utils.checkIfFileExists(powerShellExePath)) {
562+
if (!utils.checkIfFileExists(resolvedPath)) {
550563
this.setSessionFailure(
551-
"powershell.exe cannot be found or is not accessible at path " + powerShellExePath);
564+
"powershell.exe cannot be found or is not accessible at path " + resolvedPath);
552565

553566
return null;
554567
}
555568

556-
return powerShellExePath;
569+
return resolvedPath;
557570
}
558571

559572
private showSessionMenu() {

0 commit comments

Comments
 (0)