From 4f0d43052e94e11066c3556cf261fc3ffd5a9911 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 21 Sep 2025 21:41:27 +0000 Subject: [PATCH 1/3] Initial plan From 2c3f829be64a62fcc0311a0ec542566ef9610c0a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 21 Sep 2025 21:50:18 +0000 Subject: [PATCH 2/3] Add PowerShell version logging for activation debugging Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com> --- .../terminal/shells/pwsh/pwshStartup.ts | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/features/terminal/shells/pwsh/pwshStartup.ts b/src/features/terminal/shells/pwsh/pwshStartup.ts index 6e0cf31e..b3eb3fb6 100644 --- a/src/features/terminal/shells/pwsh/pwshStartup.ts +++ b/src/features/terminal/shells/pwsh/pwshStartup.ts @@ -57,6 +57,27 @@ async function isPowerShellInstalled(shell: string): Promise { } } +/** + * Detects the major version of PowerShell by executing a version query command. + * This helps with debugging activation issues since PowerShell 5.x and 7+ have different behaviors. + * @param shell The PowerShell executable name ('powershell' for Windows PowerShell or 'pwsh' for PowerShell Core/7+) + * @returns Promise resolving to the major version number as a string, or undefined if detection fails + */ +async function getPowerShellVersion(shell: 'powershell' | 'pwsh'): Promise { + try { + const command = `${shell} -Command "\$PSVersionTable.PSVersion.Major"`; + const versionOutput = await runCommand(command); + if (versionOutput && !isNaN(Number(versionOutput))) { + return versionOutput; + } + traceVerbose(`Failed to parse PowerShell version from output: ${versionOutput}`); + return undefined; + } catch (err) { + traceVerbose(`Failed to get PowerShell version for ${shell}`, err); + return undefined; + } +} + async function getProfileForShell(shell: 'powershell' | 'pwsh'): Promise { const cachedPath = getProfilePathCache(shell); if (cachedPath) { @@ -124,7 +145,8 @@ function getActivationContent(): string { ' try {', ` Invoke-Expression $env:${POWERSHELL_ENV_KEY}`, ' } catch {', - ` Write-Error "Failed to activate Python environment: $_" -ErrorAction Continue`, + ` $psVersion = $PSVersionTable.PSVersion.Major`, + ` Write-Error "Failed to activate Python environment (PowerShell $psVersion): $_" -ErrorAction Continue`, ' }', ' }', '}', @@ -219,6 +241,12 @@ export class PwshStartupProvider implements ShellStartupScriptProvider { results.set(shell, this._isPs5Installed); } else { const isInstalled = await isPowerShellInstalled(shell); + if (isInstalled) { + // Log PowerShell version for debugging activation issues + const version = await getPowerShellVersion(shell); + const versionText = version ? ` (version ${version})` : ' (version unknown)'; + traceInfo(`SHELL: ${shell} is installed${versionText}`); + } if (shell === 'pwsh') { this._isPwshInstalled = isInstalled; } else { From b3240de308e46e64f89a3207d7202a14ee51c96c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Oct 2025 03:04:34 +0000 Subject: [PATCH 3/3] Use shorter -c flag for PowerShell command Changed from -Command to -c as suggested in review. Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com> --- src/features/terminal/shells/pwsh/pwshStartup.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/features/terminal/shells/pwsh/pwshStartup.ts b/src/features/terminal/shells/pwsh/pwshStartup.ts index b3eb3fb6..ae8bf011 100644 --- a/src/features/terminal/shells/pwsh/pwshStartup.ts +++ b/src/features/terminal/shells/pwsh/pwshStartup.ts @@ -65,7 +65,7 @@ async function isPowerShellInstalled(shell: string): Promise { */ async function getPowerShellVersion(shell: 'powershell' | 'pwsh'): Promise { try { - const command = `${shell} -Command "\$PSVersionTable.PSVersion.Major"`; + const command = `${shell} -c '\$PSVersionTable.PSVersion.Major'`; const versionOutput = await runCommand(command); if (versionOutput && !isNaN(Number(versionOutput))) { return versionOutput;