Skip to content

Commit 712a3ee

Browse files
authored
Merge pull request microsoft#208425 from microsoft/tyriar/205744
Wait for cmd detection if running command at start up
2 parents d848ebe + 1a6f5b6 commit 712a3ee

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/vs/workbench/contrib/terminal/browser/terminalInstance.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,10 +824,29 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
824824
}
825825

826826
async runCommand(commandLine: string, shouldExecute: boolean): Promise<void> {
827+
let commandDetection = this.capabilities.get(TerminalCapability.CommandDetection);
828+
829+
// Await command detection if the terminal is starting up
830+
if (!commandDetection && (this._processManager.processState === ProcessState.Uninitialized || this._processManager.processState === ProcessState.Launching)) {
831+
const store = new DisposableStore();
832+
await Promise.race([
833+
new Promise<void>(r => {
834+
store.add(this.capabilities.onDidAddCapabilityType(e => {
835+
if (e === TerminalCapability.CommandDetection) {
836+
commandDetection = this.capabilities.get(TerminalCapability.CommandDetection);
837+
r();
838+
}
839+
}));
840+
}),
841+
timeout(2000),
842+
]);
843+
store.dispose();
844+
}
845+
827846
// Determine whether to send ETX (ctrl+c) before running the command. This should always
828847
// happen unless command detection can reliably say that a command is being entered and
829848
// there is no content in the prompt
830-
if (this.capabilities.get(TerminalCapability.CommandDetection)?.hasInput !== false) {
849+
if (commandDetection?.hasInput !== false) {
831850
await this.sendText('\x03', false);
832851
// Wait a little before running the command to avoid the sequences being echoed while the ^C
833852
// is being evaluated

0 commit comments

Comments
 (0)