From a488ec4b3aea32a8e4d2f2c85be7fe74c536f03e Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Fri, 24 Oct 2025 04:10:38 +1100 Subject: [PATCH 1/3] Avoid waiting for shell integration --- .../copilotCLITerminalIntegration.ts | 25 +++---------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/src/extension/chatSessions/vscode-node/copilotCLITerminalIntegration.ts b/src/extension/chatSessions/vscode-node/copilotCLITerminalIntegration.ts index 4817b3a7ed..b4adb64b86 100644 --- a/src/extension/chatSessions/vscode-node/copilotCLITerminalIntegration.ts +++ b/src/extension/chatSessions/vscode-node/copilotCLITerminalIntegration.ts @@ -159,33 +159,14 @@ ELECTRON_RUN_AS_NODE=1 "${process.execPath}" "${path.join(storageLocation, COPIL } private async sendCommandToTerminal(terminal: Terminal, command: string, waitForPythonActivation: boolean) { - // Wait for shell integration to be available - const shellIntegrationTimeout = 3000; - let shellIntegrationAvailable = false; - const integrationPromise = new Promise((resolve) => { - const disposable = this._register(this.terminalService.onDidChangeTerminalShellIntegration(e => { - if (e.terminal === terminal && e.shellIntegration) { - shellIntegrationAvailable = true; - disposable.dispose(); - resolve(); - } - })); - - this._register(disposableTimeout(() => { - disposable.dispose(); - resolve(); - }, shellIntegrationTimeout)); - }); - - await integrationPromise; - if (waitForPythonActivation) { // Wait for python extension to send its initialization commands. // Else if we send too early, the copilot command might not get executed properly. - await new Promise(resolve => this._register(disposableTimeout(resolve, 500))); // Wait a bit to ensure the terminal is ready + // Wait a bit to ensure the terminal is ready to accept new commands (else we could end up with `source .venv/bin/activatecopilot`) + await new Promise(resolve => this._register(disposableTimeout(resolve, 500))); } - if (shellIntegrationAvailable && terminal.shellIntegration) { + if (terminal.shellIntegration) { terminal.shellIntegration.executeCommand(command); } else { terminal.sendText(command); From 939c735e158a95b720171795944c5403f263c1d6 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Fri, 24 Oct 2025 04:12:47 +1100 Subject: [PATCH 2/3] Updates --- .../copilotCLITerminalIntegration.ts | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/extension/chatSessions/vscode-node/copilotCLITerminalIntegration.ts b/src/extension/chatSessions/vscode-node/copilotCLITerminalIntegration.ts index b4adb64b86..80d549a5a4 100644 --- a/src/extension/chatSessions/vscode-node/copilotCLITerminalIntegration.ts +++ b/src/extension/chatSessions/vscode-node/copilotCLITerminalIntegration.ts @@ -159,14 +159,33 @@ ELECTRON_RUN_AS_NODE=1 "${process.execPath}" "${path.join(storageLocation, COPIL } private async sendCommandToTerminal(terminal: Terminal, command: string, waitForPythonActivation: boolean) { + // Wait for shell integration to be available + const shellIntegrationTimeout = 3000; + let shellIntegrationAvailable = terminal.shellIntegration ? true : false; + const integrationPromise = shellIntegrationAvailable ? Promise.resolve() : new Promise((resolve) => { + const disposable = this._register(this.terminalService.onDidChangeTerminalShellIntegration(e => { + if (e.terminal === terminal && e.shellIntegration) { + shellIntegrationAvailable = true; + disposable.dispose(); + resolve(); + } + })); + + this._register(disposableTimeout(() => { + disposable.dispose(); + resolve(); + }, shellIntegrationTimeout)); + }); + + await integrationPromise; + if (waitForPythonActivation) { // Wait for python extension to send its initialization commands. // Else if we send too early, the copilot command might not get executed properly. - // Wait a bit to ensure the terminal is ready to accept new commands (else we could end up with `source .venv/bin/activatecopilot`) - await new Promise(resolve => this._register(disposableTimeout(resolve, 500))); + await new Promise(resolve => this._register(disposableTimeout(resolve, 500))); // Wait a bit to ensure the terminal is ready } - if (terminal.shellIntegration) { + if (shellIntegrationAvailable && terminal.shellIntegration) { terminal.shellIntegration.executeCommand(command); } else { terminal.sendText(command); From 51fcbc1b3db438e4701551e100147bb2d5e81fd3 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Fri, 24 Oct 2025 04:13:17 +1100 Subject: [PATCH 3/3] Updates --- .../chatSessions/vscode-node/copilotCLITerminalIntegration.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extension/chatSessions/vscode-node/copilotCLITerminalIntegration.ts b/src/extension/chatSessions/vscode-node/copilotCLITerminalIntegration.ts index 80d549a5a4..bd909d865d 100644 --- a/src/extension/chatSessions/vscode-node/copilotCLITerminalIntegration.ts +++ b/src/extension/chatSessions/vscode-node/copilotCLITerminalIntegration.ts @@ -185,7 +185,7 @@ ELECTRON_RUN_AS_NODE=1 "${process.execPath}" "${path.join(storageLocation, COPIL await new Promise(resolve => this._register(disposableTimeout(resolve, 500))); // Wait a bit to ensure the terminal is ready } - if (shellIntegrationAvailable && terminal.shellIntegration) { + if (terminal.shellIntegration) { terminal.shellIntegration.executeCommand(command); } else { terminal.sendText(command);