From dbb647c6c847d3564273093bc546653455037a70 Mon Sep 17 00:00:00 2001 From: Andy Jordan <2226434+andyleejordan@users.noreply.github.com> Date: Thu, 10 Oct 2024 14:42:32 -0700 Subject: [PATCH] Set expected shell integration environment variables --- src/process.ts | 16 ++++++++++++++++ src/session.ts | 2 ++ 2 files changed, 18 insertions(+) diff --git a/src/process.ts b/src/process.ts index 6cd38e059a..d363c8e2ee 100644 --- a/src/process.ts +++ b/src/process.ts @@ -28,6 +28,7 @@ export class PowerShellProcess { public exePath: string, private bundledModulesPath: string, private isTemp: boolean, + private shellIntegrationEnabled: boolean, private logger: ILogger, private startPsesArgs: string, private sessionFilePath: vscode.Uri, @@ -99,12 +100,27 @@ export class PowerShellProcess { // Make sure no old session file exists await this.deleteSessionFile(this.sessionFilePath); + // When VS Code shell integration is enabled, the script expects certain + // variables to be added to the environment. + let envMixin = undefined; + if (this.shellIntegrationEnabled) { + envMixin = { + "VSCODE_INJECTION": "1", + // There is no great way to check if we are running stable VS + // Code. Since this is used to disable experimental features, we + // default to stable unless we're definitely running Insiders. + "VSCODE_STABLE": vscode.env.appName.includes("Insiders") ? "0" : "1", + // Maybe one day we can set VSCODE_NONCE... + }; + } + // Launch PowerShell in the integrated terminal const terminalOptions: vscode.TerminalOptions = { name: this.isTemp ? `${PowerShellProcess.title} (TEMP)` : PowerShellProcess.title, shellPath: this.exePath, shellArgs: powerShellArgs, cwd: await validateCwdSetting(this.logger), + env: envMixin, iconPath: new vscode.ThemeIcon("terminal-powershell"), isTransient: true, hideFromUser: this.sessionSettings.integratedConsole.startInBackground, diff --git a/src/session.ts b/src/session.ts index 73186237fe..a127f456ce 100644 --- a/src/session.ts +++ b/src/session.ts @@ -351,6 +351,7 @@ export class SessionManager implements Middleware { this.PowerShellExeDetails.exePath, bundledModulesPath, true, + false, this.logger, this.getEditorServicesArgs(bundledModulesPath, this.PowerShellExeDetails) + "-DebugServiceOnly ", this.getNewSessionFilePath(), @@ -536,6 +537,7 @@ export class SessionManager implements Middleware { powerShellExeDetails.exePath, bundledModulesPath, false, + this.shellIntegrationEnabled, this.logger, this.getEditorServicesArgs(bundledModulesPath, powerShellExeDetails), this.getNewSessionFilePath(),