Skip to content

Commit 140b211

Browse files
authored
Merge pull request microsoft#209041 from microsoft/tyriar/208648
Move exitCode into TerminalShellExecutionEndEvent
2 parents ff1fc11 + a50a6bf commit 140b211

File tree

2 files changed

+21
-24
lines changed

2 files changed

+21
-24
lines changed

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

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export interface IExtHostTerminalShellIntegration extends ExtHostTerminalShellIn
1818

1919
readonly onDidChangeTerminalShellIntegration: Event<vscode.TerminalShellIntegrationChangeEvent>;
2020
readonly onDidStartTerminalShellExecution: Event<vscode.TerminalShellExecution>;
21-
readonly onDidEndTerminalShellExecution: Event<vscode.TerminalShellExecution>;
21+
readonly onDidEndTerminalShellExecution: Event<vscode.TerminalShellExecutionEndEvent>;
2222
}
2323
export const IExtHostTerminalShellIntegration = createDecorator<IExtHostTerminalShellIntegration>('IExtHostTerminalShellIntegration');
2424

@@ -34,7 +34,7 @@ export class ExtHostTerminalShellIntegration extends Disposable implements IExtH
3434
readonly onDidChangeTerminalShellIntegration = this._onDidChangeTerminalShellIntegration.event;
3535
protected readonly _onDidStartTerminalShellExecution = new Emitter<vscode.TerminalShellExecution>();
3636
readonly onDidStartTerminalShellExecution = this._onDidStartTerminalShellExecution.event;
37-
protected readonly _onDidEndTerminalShellExecution = new Emitter<vscode.TerminalShellExecution>();
37+
protected readonly _onDidEndTerminalShellExecution = new Emitter<vscode.TerminalShellExecutionEndEvent>();
3838
readonly onDidEndTerminalShellExecution = this._onDidEndTerminalShellExecution.event;
3939

4040
constructor(
@@ -91,7 +91,7 @@ export class ExtHostTerminalShellIntegration extends Disposable implements IExtH
9191
this._activeShellIntegrations.set(instanceId, shellIntegration);
9292
shellIntegration.store.add(terminal.onWillDispose(() => this._activeShellIntegrations.get(instanceId)?.dispose()));
9393
shellIntegration.store.add(shellIntegration.onDidRequestShellExecution(commandLine => this._proxy.$executeCommand(instanceId, commandLine)));
94-
shellIntegration.store.add(shellIntegration.onDidRequestEndExecution(e => this._onDidEndTerminalShellExecution.fire(e.value)));
94+
shellIntegration.store.add(shellIntegration.onDidRequestEndExecution(e => this._onDidEndTerminalShellExecution.fire(e)));
9595
shellIntegration.store.add(shellIntegration.onDidRequestChangeShellIntegration(e => this._onDidChangeTerminalShellIntegration.fire(e)));
9696
terminal.shellIntegration = shellIntegration.value;
9797
}
@@ -144,7 +144,7 @@ class InternalTerminalShellIntegration extends Disposable {
144144
readonly onDidRequestChangeShellIntegration = this._onDidRequestChangeShellIntegration.event;
145145
protected readonly _onDidRequestShellExecution = this._register(new Emitter<string>());
146146
readonly onDidRequestShellExecution = this._onDidRequestShellExecution.event;
147-
protected readonly _onDidRequestEndExecution = this._register(new Emitter<InternalTerminalShellExecution>());
147+
protected readonly _onDidRequestEndExecution = this._register(new Emitter<vscode.TerminalShellExecutionEndEvent>());
148148
readonly onDidRequestEndExecution = this._onDidRequestEndExecution.event;
149149

150150
constructor(
@@ -173,7 +173,7 @@ class InternalTerminalShellIntegration extends Disposable {
173173
} else {
174174
if (this._currentExecution) {
175175
this._currentExecution.endExecution(undefined, undefined);
176-
this._onDidRequestEndExecution.fire(this._currentExecution);
176+
this._onDidRequestEndExecution.fire({ execution: this._currentExecution.value, exitCode: undefined });
177177
}
178178
this._currentExecution = new InternalTerminalShellExecution(this._terminal, commandLine, cwd);
179179
this._onDidStartTerminalShellExecution.fire(this._currentExecution.value);
@@ -188,7 +188,7 @@ class InternalTerminalShellIntegration extends Disposable {
188188
endShellExecution(commandLine: string | undefined, exitCode: number | undefined): void {
189189
if (this._currentExecution) {
190190
this._currentExecution.endExecution(commandLine, exitCode);
191-
this._onDidRequestEndExecution.fire(this._currentExecution);
191+
this._onDidRequestEndExecution.fire({ execution: this._currentExecution.value, exitCode });
192192
this._currentExecution = undefined;
193193
}
194194
}
@@ -212,8 +212,7 @@ class InternalTerminalShellIntegration extends Disposable {
212212
class InternalTerminalShellExecution {
213213
private _dataStream: ShellExecutionDataStream | undefined;
214214

215-
private readonly _exitCode: Promise<number | undefined>;
216-
private _exitCodeResolve: ((exitCode: number | undefined) => void) | undefined;
215+
private _ended: boolean = false;
217216

218217
readonly value: vscode.TerminalShellExecution;
219218

@@ -222,10 +221,6 @@ class InternalTerminalShellExecution {
222221
private _commandLine: string | undefined,
223222
readonly cwd: URI | string | undefined,
224223
) {
225-
this._exitCode = new Promise<number | undefined>(resolve => {
226-
this._exitCodeResolve = resolve;
227-
});
228-
229224
const that = this;
230225
this.value = {
231226
get terminal(): vscode.Terminal {
@@ -237,9 +232,6 @@ class InternalTerminalShellExecution {
237232
get cwd(): URI | string | undefined {
238233
return cwd;
239234
},
240-
get exitCode(): Promise<number | undefined> {
241-
return that._exitCode;
242-
},
243235
createDataStream(): AsyncIterable<string> {
244236
return that._createDataStream();
245237
}
@@ -248,7 +240,7 @@ class InternalTerminalShellExecution {
248240

249241
private _createDataStream(): AsyncIterable<string> {
250242
if (!this._dataStream) {
251-
if (this._exitCodeResolve === undefined) {
243+
if (this._ended) {
252244
return AsyncIterableObject.EMPTY;
253245
}
254246
this._dataStream = new ShellExecutionDataStream();
@@ -266,8 +258,7 @@ class InternalTerminalShellExecution {
266258
}
267259
this._dataStream?.endExecution();
268260
this._dataStream = undefined;
269-
this._exitCodeResolve?.(exitCode);
270-
this._exitCodeResolve = undefined;
261+
this._ended = true;
271262
}
272263
}
273264

src/vscode-dts/vscode.proposed.terminalShellIntegration.d.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ declare module 'vscode' {
3737
*/
3838
readonly cwd: Uri | string | undefined;
3939

40-
/**
41-
* The exit code reported by the shell.
42-
*/
43-
readonly exitCode: Thenable<number | undefined>;
44-
4540
/**
4641
* Creates a stream of raw data (including escape sequences) that is written to the
4742
* terminal. This will only include data that was written after `stream` was called for the
@@ -184,6 +179,17 @@ declare module 'vscode' {
184179
readonly shellIntegration: TerminalShellIntegration;
185180
}
186181

182+
export interface TerminalShellExecutionEndEvent {
183+
/**
184+
* The terminal shell execution that has ended.
185+
*/
186+
readonly execution: TerminalShellExecution;
187+
/**
188+
* The exit code reported by the shell.
189+
*/
190+
readonly exitCode: number | undefined;
191+
}
192+
187193
export namespace window {
188194
/**
189195
* Fires when shell integration activates or one of its properties changes in a terminal.
@@ -202,6 +208,6 @@ declare module 'vscode' {
202208
* [shell integration](https://code.visualstudio.com/docs/terminal/shell-integration) is
203209
* activated for the terminal.
204210
*/
205-
export const onDidEndTerminalShellExecution: Event<TerminalShellExecution>;
211+
export const onDidEndTerminalShellExecution: Event<TerminalShellExecutionEndEvent>;
206212
}
207213
}

0 commit comments

Comments
 (0)