@@ -74,7 +74,9 @@ export class ExtHostTerminalShellIntegration extends Disposable implements IExtH
74
74
// console.log('*** onDidEndTerminalShellExecution', e);
75
75
// });
76
76
// setTimeout(() => {
77
+ // console.log('before executeCommand(\"echo hello\")');
77
78
// Array.from(this._activeShellIntegrations.values())[0].value.executeCommand('echo hello');
79
+ // console.log('after executeCommand(\"echo hello\")');
78
80
// }, 4000);
79
81
}
80
82
@@ -160,23 +162,29 @@ class InternalTerminalShellIntegration extends Disposable {
160
162
} ,
161
163
executeCommand ( commandLine ) : vscode . TerminalShellExecution {
162
164
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 ;
164
168
that . _ignoreNextExecution = true ;
165
169
return execution ;
166
170
}
167
171
} ;
168
172
}
169
173
170
- startShellExecution ( commandLine : string , cwd : URI | string | undefined ) : InternalTerminalShellExecution {
174
+ startShellExecution ( commandLine : string , cwd : URI | string | undefined , fireEventInMicrotask ?: boolean ) : InternalTerminalShellExecution {
171
175
if ( this . _ignoreNextExecution && this . _currentExecution ) {
172
176
this . _ignoreNextExecution = false ;
173
177
} else {
174
178
if ( this . _currentExecution ) {
175
179
this . _currentExecution . endExecution ( undefined , undefined ) ;
176
180
this . _onDidRequestEndExecution . fire ( this . _currentExecution ) ;
177
181
}
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
+ }
180
188
}
181
189
return this . _currentExecution ;
182
190
}
0 commit comments