Skip to content

Commit e61b612

Browse files
Set expected shell integration environment variables (#5062)
1 parent 68a073a commit e61b612

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/process.ts

+16
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export class PowerShellProcess {
2828
public exePath: string,
2929
private bundledModulesPath: string,
3030
private isTemp: boolean,
31+
private shellIntegrationEnabled: boolean,
3132
private logger: ILogger,
3233
private startPsesArgs: string,
3334
private sessionFilePath: vscode.Uri,
@@ -99,12 +100,27 @@ export class PowerShellProcess {
99100
// Make sure no old session file exists
100101
await this.deleteSessionFile(this.sessionFilePath);
101102

103+
// When VS Code shell integration is enabled, the script expects certain
104+
// variables to be added to the environment.
105+
let envMixin = undefined;
106+
if (this.shellIntegrationEnabled) {
107+
envMixin = {
108+
"VSCODE_INJECTION": "1",
109+
// There is no great way to check if we are running stable VS
110+
// Code. Since this is used to disable experimental features, we
111+
// default to stable unless we're definitely running Insiders.
112+
"VSCODE_STABLE": vscode.env.appName.includes("Insiders") ? "0" : "1",
113+
// Maybe one day we can set VSCODE_NONCE...
114+
};
115+
}
116+
102117
// Launch PowerShell in the integrated terminal
103118
const terminalOptions: vscode.TerminalOptions = {
104119
name: this.isTemp ? `${PowerShellProcess.title} (TEMP)` : PowerShellProcess.title,
105120
shellPath: this.exePath,
106121
shellArgs: powerShellArgs,
107122
cwd: await validateCwdSetting(this.logger),
123+
env: envMixin,
108124
iconPath: new vscode.ThemeIcon("terminal-powershell"),
109125
isTransient: true,
110126
hideFromUser: this.sessionSettings.integratedConsole.startInBackground,

src/session.ts

+2
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ export class SessionManager implements Middleware {
351351
this.PowerShellExeDetails.exePath,
352352
bundledModulesPath,
353353
true,
354+
false,
354355
this.logger,
355356
this.getEditorServicesArgs(bundledModulesPath, this.PowerShellExeDetails) + "-DebugServiceOnly ",
356357
this.getNewSessionFilePath(),
@@ -536,6 +537,7 @@ export class SessionManager implements Middleware {
536537
powerShellExeDetails.exePath,
537538
bundledModulesPath,
538539
false,
540+
this.shellIntegrationEnabled,
539541
this.logger,
540542
this.getEditorServicesArgs(bundledModulesPath, powerShellExeDetails),
541543
this.getNewSessionFilePath(),

0 commit comments

Comments
 (0)