From a25f1d949ddf0a0fc05b987dc7599cc77a56c77f Mon Sep 17 00:00:00 2001 From: Eric Wheeler Date: Tue, 11 Mar 2025 20:53:41 -0700 Subject: [PATCH 1/3] fix: add PowerShell-specific command handling PowerShell requires special handling for command output due to two issues: - A sleep delay is required to prevent the ]633;D marker from losing the original output - A counter is needed to work around a bug where identical commands are not executed Changes: - Add cmdCounter to Terminal class for unique command tracking - Add PowerShell detection via platform and default shell profile - Add sleep delay to ensure output is captured before command completion Signed-off-by: Eric Wheeler --- src/integrations/terminal/Terminal.ts | 1 + src/integrations/terminal/TerminalProcess.ts | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/integrations/terminal/Terminal.ts b/src/integrations/terminal/Terminal.ts index e768d79397..531300aab9 100644 --- a/src/integrations/terminal/Terminal.ts +++ b/src/integrations/terminal/Terminal.ts @@ -11,6 +11,7 @@ export class Terminal { private streamClosed: boolean public process?: TerminalProcess public taskId?: string + public cmdCounter: number = 0 public completedProcesses: TerminalProcess[] = [] private initialCwd: string diff --git a/src/integrations/terminal/TerminalProcess.ts b/src/integrations/terminal/TerminalProcess.ts index c5e1c901b5..468bfebabb 100644 --- a/src/integrations/terminal/TerminalProcess.ts +++ b/src/integrations/terminal/TerminalProcess.ts @@ -276,7 +276,20 @@ export class TerminalProcess extends EventEmitter { }) // Execute command - terminal.shellIntegration.executeCommand(command) + const defaultWindowsShellProfile = vscode.workspace + .getConfiguration("terminal.integrated.defaultProfile") + .get("windows") + const isPowerShell = + process.platform === "win32" && + (defaultWindowsShellProfile === null || + (defaultWindowsShellProfile as string)?.toLowerCase().includes("powershell")) + if (isPowerShell) { + terminal.shellIntegration.executeCommand( + `${command} ; ${this.terminalInfo.cmdCounter++} > $null; start-sleep -milliseconds 150`, + ) + } else { + terminal.shellIntegration.executeCommand(command) + } this.isHot = true // Wait for stream to be available From f29a5fa9a4dff9fdb54931b97392500f35f793d9 Mon Sep 17 00:00:00 2001 From: Eric Wheeler Date: Tue, 11 Mar 2025 21:03:07 -0700 Subject: [PATCH 2/3] test: add workspace configuration mock for terminal tests Mock VSCode workspace configuration to handle PowerShell detection in terminal tests. This prevents TypeError when accessing getConfiguration() in TerminalProcess.run() Signed-off-by: Eric Wheeler --- .../terminal/__tests__/TerminalProcessExec.test.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/integrations/terminal/__tests__/TerminalProcessExec.test.ts b/src/integrations/terminal/__tests__/TerminalProcessExec.test.ts index 0e719daa1b..afe6a4513a 100644 --- a/src/integrations/terminal/__tests__/TerminalProcessExec.test.ts +++ b/src/integrations/terminal/__tests__/TerminalProcessExec.test.ts @@ -14,6 +14,11 @@ jest.mock("vscode", () => { } return { + workspace: { + getConfiguration: jest.fn().mockReturnValue({ + get: jest.fn().mockReturnValue(null), + }), + }, window: { createTerminal: jest.fn(), onDidStartTerminalShellExecution: jest.fn().mockImplementation((handler) => { From 50b7326aa0d0718ced75e5eee34d89160b9eea87 Mon Sep 17 00:00:00 2001 From: Eric Wheeler Date: Tue, 11 Mar 2025 21:08:53 -0700 Subject: [PATCH 3/3] fix: add workspace configuration mock to TerminalProcess test Add VSCode workspace configuration mock to TerminalProcess.test.ts to handle PowerShell detection in terminal tests, matching the fix in TerminalProcessExec.test.ts Signed-off-by: Eric Wheeler --- src/integrations/terminal/__tests__/TerminalProcess.test.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/integrations/terminal/__tests__/TerminalProcess.test.ts b/src/integrations/terminal/__tests__/TerminalProcess.test.ts index 702166838e..82bfe23659 100644 --- a/src/integrations/terminal/__tests__/TerminalProcess.test.ts +++ b/src/integrations/terminal/__tests__/TerminalProcess.test.ts @@ -10,6 +10,11 @@ import { TerminalRegistry } from "../TerminalRegistry" const mockCreateTerminal = jest.fn() jest.mock("vscode", () => ({ + workspace: { + getConfiguration: jest.fn().mockReturnValue({ + get: jest.fn().mockReturnValue(null), + }), + }, window: { createTerminal: (...args: any[]) => { mockCreateTerminal(...args)