Skip to content

Commit 7e57821

Browse files
authored
Terminal and part of the debug changes needed to respond to cancelling a prelaunch task (microsoft#82255)
Part of microsoft#81768
1 parent 1dd67cb commit 7e57821

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/vs/workbench/contrib/debug/browser/debugService.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,9 +780,17 @@ export class DebugService implements IDebugService {
780780
});
781781
const taskPromise = this.taskService.run(task);
782782
if (task.configurationProperties.isBackground) {
783-
return new Promise((c, e) => once(e => e.kind === TaskEventKind.Inactive && e.taskId === task._id, this.taskService.onDidStateChange)(() => {
783+
return new Promise((c, e) => once(e => {
784+
// When a task isBackground it will go inactive when it is safe to launch.
785+
// But when a background task is terminated by the user, it will also fire an inactive event.
786+
// This means that we will not get to see the real exit code from running the task (undefined when terminated by the user).
787+
// Catch the ProcessEnded event here, which occurs before inactive, and capture the exit code to prevent this.
788+
return (e.kind === TaskEventKind.Inactive
789+
|| (e.kind === TaskEventKind.ProcessEnded && e.exitCode === undefined))
790+
&& e.taskId === task._id;
791+
}, this.taskService.onDidStateChange)(e => {
784792
taskStarted = true;
785-
c(null);
793+
c(e.kind === TaskEventKind.ProcessEnded ? { exitCode: e.exitCode } : null);
786794
}));
787795
}
788796

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ export interface ITerminalInstance {
226226
* is the processes' exit code, an exit code of null means the process was killed as a result of
227227
* the ITerminalInstance being disposed.
228228
*/
229-
onExit: Event<number>;
229+
onExit: Event<number | undefined>;
230230

231231
processReady: Promise<void>;
232232

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
232232
public get commandTracker(): CommandTrackerAddon | undefined { return this._commandTrackerAddon; }
233233
public get navigationMode(): INavigationMode | undefined { return this._navigationModeAddon; }
234234

235-
private readonly _onExit = new Emitter<number>();
236-
public get onExit(): Event<number> { return this._onExit.event; }
235+
private readonly _onExit = new Emitter<number | undefined>();
236+
public get onExit(): Event<number | undefined> { return this._onExit.event; }
237237
private readonly _onDisposed = new Emitter<ITerminalInstance>();
238238
public get onDisposed(): Event<ITerminalInstance> { return this._onDisposed.event; }
239239
private readonly _onFocused = new Emitter<ITerminalInstance>();
@@ -1102,7 +1102,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
11021102
}
11031103
}
11041104

1105-
this._onExit.fire(exitCode || 0);
1105+
this._onExit.fire(exitCode);
11061106
}
11071107

11081108
private _attachPressAnyKeyToCloseListener(xterm: XTermTerminal) {

0 commit comments

Comments
 (0)