Skip to content

Commit 82f8d08

Browse files
authored
Merge pull request microsoft#209044 from microsoft/tyriar/208650
Fire onDidStartTerminalShellExecution from executeCommand in microtask
2 parents 7b2cc73 + 45e81d4 commit 82f8d08

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/vs/workbench/api/common/extHostTerminalShellIntegration.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ export class ExtHostTerminalShellIntegration extends Disposable implements IExtH
7474
// console.log('*** onDidEndTerminalShellExecution', e);
7575
// });
7676
// setTimeout(() => {
77+
// console.log('before executeCommand(\"echo hello\")');
7778
// Array.from(this._activeShellIntegrations.values())[0].value.executeCommand('echo hello');
79+
// console.log('after executeCommand(\"echo hello\")');
7880
// }, 4000);
7981
}
8082

@@ -160,23 +162,29 @@ class InternalTerminalShellIntegration extends Disposable {
160162
},
161163
executeCommand(commandLine): vscode.TerminalShellExecution {
162164
that._onDidRequestShellExecution.fire(commandLine);
163-
const execution = that.startShellExecution(commandLine, that._cwd).value;
165+
// Fire the event in a microtask to allow the extension to use the execution before
166+
// the start event fires
167+
const execution = that.startShellExecution(commandLine, that._cwd, true).value;
164168
that._ignoreNextExecution = true;
165169
return execution;
166170
}
167171
};
168172
}
169173

170-
startShellExecution(commandLine: string, cwd: URI | string | undefined): InternalTerminalShellExecution {
174+
startShellExecution(commandLine: string, cwd: URI | string | undefined, fireEventInMicrotask?: boolean): InternalTerminalShellExecution {
171175
if (this._ignoreNextExecution && this._currentExecution) {
172176
this._ignoreNextExecution = false;
173177
} else {
174178
if (this._currentExecution) {
175179
this._currentExecution.endExecution(undefined, undefined);
176180
this._onDidRequestEndExecution.fire({ execution: this._currentExecution.value, exitCode: undefined });
177181
}
178-
this._currentExecution = new InternalTerminalShellExecution(this._terminal, commandLine, cwd);
179-
this._onDidStartTerminalShellExecution.fire(this._currentExecution.value);
182+
const currentExecution = this._currentExecution = new InternalTerminalShellExecution(this._terminal, commandLine, cwd);
183+
if (fireEventInMicrotask) {
184+
queueMicrotask(() => this._onDidStartTerminalShellExecution.fire(currentExecution.value));
185+
} else {
186+
this._onDidStartTerminalShellExecution.fire(this._currentExecution.value);
187+
}
180188
}
181189
return this._currentExecution;
182190
}

0 commit comments

Comments
 (0)