Skip to content

Commit dd3b65f

Browse files
committed
Only show 'task already running' message when task is visible
If the task is running but not visible, show it Fixes microsoft#84794
1 parent 419360d commit dd3b65f

4 files changed

Lines changed: 30 additions & 27 deletions

File tree

src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,23 +1260,22 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
12601260
if (executeResult.kind === TaskExecuteKind.Active) {
12611261
let active = executeResult.active;
12621262
if (active && active.same) {
1263-
let message;
1264-
if (active.background) {
1265-
message = nls.localize('TaskSystem.activeSame.background', 'The task \'{0}\' is already active and in background mode.', executeResult.task.getQualifiedLabel());
1263+
if (this._taskSystem?.isTaskVisible(executeResult.task)) {
1264+
const message = nls.localize('TaskSystem.activeSame.noBackground', 'The task \'{0}\' is already active.', executeResult.task.getQualifiedLabel());
1265+
this.notificationService.prompt(Severity.Info, message,
1266+
[{
1267+
label: nls.localize('terminateTask', "Terminate Task"),
1268+
run: () => this.terminate(executeResult.task)
1269+
},
1270+
{
1271+
label: nls.localize('restartTask', "Restart Task"),
1272+
run: () => this.restart(executeResult.task)
1273+
}],
1274+
{ sticky: true }
1275+
);
12661276
} else {
1267-
message = nls.localize('TaskSystem.activeSame.noBackground', 'The task \'{0}\' is already active.', executeResult.task.getQualifiedLabel());
1277+
this._taskSystem?.revealTask(executeResult.task);
12681278
}
1269-
this.notificationService.prompt(Severity.Info, message,
1270-
[{
1271-
label: nls.localize('terminateTask', "Terminate Task"),
1272-
run: () => this.terminate(executeResult.task)
1273-
},
1274-
{
1275-
label: nls.localize('restartTask', "Restart Task"),
1276-
run: () => this.restart(executeResult.task)
1277-
}],
1278-
{ sticky: true }
1279-
);
12801279
} else {
12811280
throw new TaskError(Severity.Warning, nls.localize('TaskSystem.active', 'There is already a task running. Terminate it first before executing another task.'), TaskErrors.RunningTask);
12821281
}

src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,6 @@ export class TerminalTaskSystem implements ITaskSystem {
208208
this.currentTask = new VerifiedTask(task, resolver, trigger);
209209
let terminalData = this.activeTasks[task.getMapKey()];
210210
if (terminalData && terminalData.promise) {
211-
let reveal = RevealKind.Always;
212-
let focus = false;
213-
if (CustomTask.is(task) || ContributedTask.is(task)) {
214-
reveal = task.command.presentation!.reveal;
215-
focus = task.command.presentation!.focus;
216-
}
217-
if (reveal === RevealKind.Always || focus) {
218-
this.terminalService.setActiveInstance(terminalData.terminal);
219-
this.terminalService.showPanel(focus);
220-
}
221211
this.lastTask = this.currentTask;
222212
return { kind: TaskExecuteKind.Active, task, active: { same: true, background: task.configurationProperties.isBackground! }, promise: terminalData.promise };
223213
}
@@ -256,14 +246,23 @@ export class TerminalTaskSystem implements ITaskSystem {
256246
}
257247
}
258248

259-
public revealTask(task: Task): boolean {
249+
public isTaskVisible(task: Task): boolean {
260250
let terminalData = this.activeTasks[task.getMapKey()];
261251
if (!terminalData) {
262252
return false;
263253
}
264254
const activeTerminalInstance = this.terminalService.getActiveInstance();
265255
const isPanelShowingTerminal = this.panelService.getActivePanel()?.getId() === TERMINAL_PANEL_ID;
266-
if (isPanelShowingTerminal && (activeTerminalInstance === terminalData.terminal)) {
256+
return isPanelShowingTerminal && (activeTerminalInstance?.id === terminalData.terminal.id);
257+
}
258+
259+
260+
public revealTask(task: Task): boolean {
261+
let terminalData = this.activeTasks[task.getMapKey()];
262+
if (!terminalData) {
263+
return false;
264+
}
265+
if (this.isTaskVisible(task)) {
267266
if (this.previousPanelId) {
268267
if (this.previousTerminalInstance) {
269268
this.terminalService.setActiveInstance(this.previousTerminalInstance);

src/vs/workbench/contrib/tasks/common/taskSystem.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,5 @@ export interface ITaskSystem {
139139
terminateAll(): Promise<TaskTerminateResponse[]>;
140140
revealTask(task: Task): boolean;
141141
customExecutionComplete(task: Task, result: number): Promise<void>;
142+
isTaskVisible(task: Task): boolean;
142143
}

src/vs/workbench/contrib/tasks/node/processTaskSystem.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ export class ProcessTaskSystem implements ITaskSystem {
8282
return !!this.childProcess;
8383
}
8484

85+
public isTaskVisible(): boolean {
86+
return true;
87+
}
88+
8589
public getActiveTasks(): Task[] {
8690
let result: Task[] = [];
8791
if (this.activeTask) {

0 commit comments

Comments
 (0)