From 45e81d417918032dfba803232894b58830bbebb4 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Thu, 28 Mar 2024 10:36:12 -0700 Subject: [PATCH] Fire onDidStartTerminalShellExecution from executeCommand in microtask Fixes #208650 --- .../common/extHostTerminalShellIntegration.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/api/common/extHostTerminalShellIntegration.ts b/src/vs/workbench/api/common/extHostTerminalShellIntegration.ts index 0e2a6358f13..f38477405ad 100644 --- a/src/vs/workbench/api/common/extHostTerminalShellIntegration.ts +++ b/src/vs/workbench/api/common/extHostTerminalShellIntegration.ts @@ -74,7 +74,9 @@ export class ExtHostTerminalShellIntegration extends Disposable implements IExtH // console.log('*** onDidEndTerminalShellExecution', e); // }); // setTimeout(() => { + // console.log('before executeCommand(\"echo hello\")'); // Array.from(this._activeShellIntegrations.values())[0].value.executeCommand('echo hello'); + // console.log('after executeCommand(\"echo hello\")'); // }, 4000); } @@ -160,14 +162,16 @@ class InternalTerminalShellIntegration extends Disposable { }, executeCommand(commandLine): vscode.TerminalShellExecution { that._onDidRequestShellExecution.fire(commandLine); - const execution = that.startShellExecution(commandLine, that._cwd).value; + // Fire the event in a microtask to allow the extension to use the execution before + // the start event fires + const execution = that.startShellExecution(commandLine, that._cwd, true).value; that._ignoreNextExecution = true; return execution; } }; } - startShellExecution(commandLine: string, cwd: URI | string | undefined): InternalTerminalShellExecution { + startShellExecution(commandLine: string, cwd: URI | string | undefined, fireEventInMicrotask?: boolean): InternalTerminalShellExecution { if (this._ignoreNextExecution && this._currentExecution) { this._ignoreNextExecution = false; } else { @@ -175,8 +179,12 @@ class InternalTerminalShellIntegration extends Disposable { this._currentExecution.endExecution(undefined, undefined); this._onDidRequestEndExecution.fire(this._currentExecution); } - this._currentExecution = new InternalTerminalShellExecution(this._terminal, commandLine, cwd); - this._onDidStartTerminalShellExecution.fire(this._currentExecution.value); + const currentExecution = this._currentExecution = new InternalTerminalShellExecution(this._terminal, commandLine, cwd); + if (fireEventInMicrotask) { + queueMicrotask(() => this._onDidStartTerminalShellExecution.fire(currentExecution.value)); + } else { + this._onDidStartTerminalShellExecution.fire(this._currentExecution.value); + } } return this._currentExecution; }