diff --git a/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts b/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts index 5fe66a52075..1dc520e61d6 100644 --- a/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts +++ b/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts @@ -1260,23 +1260,22 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer if (executeResult.kind === TaskExecuteKind.Active) { let active = executeResult.active; if (active && active.same) { - let message; - if (active.background) { - message = nls.localize('TaskSystem.activeSame.background', 'The task \'{0}\' is already active and in background mode.', executeResult.task.getQualifiedLabel()); + if (this._taskSystem?.isTaskVisible(executeResult.task)) { + const message = nls.localize('TaskSystem.activeSame.noBackground', 'The task \'{0}\' is already active.', executeResult.task.getQualifiedLabel()); + this.notificationService.prompt(Severity.Info, message, + [{ + label: nls.localize('terminateTask', "Terminate Task"), + run: () => this.terminate(executeResult.task) + }, + { + label: nls.localize('restartTask', "Restart Task"), + run: () => this.restart(executeResult.task) + }], + { sticky: true } + ); } else { - message = nls.localize('TaskSystem.activeSame.noBackground', 'The task \'{0}\' is already active.', executeResult.task.getQualifiedLabel()); + this._taskSystem?.revealTask(executeResult.task); } - this.notificationService.prompt(Severity.Info, message, - [{ - label: nls.localize('terminateTask', "Terminate Task"), - run: () => this.terminate(executeResult.task) - }, - { - label: nls.localize('restartTask', "Restart Task"), - run: () => this.restart(executeResult.task) - }], - { sticky: true } - ); } else { throw new TaskError(Severity.Warning, nls.localize('TaskSystem.active', 'There is already a task running. Terminate it first before executing another task.'), TaskErrors.RunningTask); } diff --git a/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts b/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts index c018ba09d3d..1f857cc1ef5 100644 --- a/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts +++ b/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts @@ -208,16 +208,6 @@ export class TerminalTaskSystem implements ITaskSystem { this.currentTask = new VerifiedTask(task, resolver, trigger); let terminalData = this.activeTasks[task.getMapKey()]; if (terminalData && terminalData.promise) { - let reveal = RevealKind.Always; - let focus = false; - if (CustomTask.is(task) || ContributedTask.is(task)) { - reveal = task.command.presentation!.reveal; - focus = task.command.presentation!.focus; - } - if (reveal === RevealKind.Always || focus) { - this.terminalService.setActiveInstance(terminalData.terminal); - this.terminalService.showPanel(focus); - } this.lastTask = this.currentTask; return { kind: TaskExecuteKind.Active, task, active: { same: true, background: task.configurationProperties.isBackground! }, promise: terminalData.promise }; } @@ -256,14 +246,23 @@ export class TerminalTaskSystem implements ITaskSystem { } } - public revealTask(task: Task): boolean { + public isTaskVisible(task: Task): boolean { let terminalData = this.activeTasks[task.getMapKey()]; if (!terminalData) { return false; } const activeTerminalInstance = this.terminalService.getActiveInstance(); const isPanelShowingTerminal = this.panelService.getActivePanel()?.getId() === TERMINAL_PANEL_ID; - if (isPanelShowingTerminal && (activeTerminalInstance === terminalData.terminal)) { + return isPanelShowingTerminal && (activeTerminalInstance?.id === terminalData.terminal.id); + } + + + public revealTask(task: Task): boolean { + let terminalData = this.activeTasks[task.getMapKey()]; + if (!terminalData) { + return false; + } + if (this.isTaskVisible(task)) { if (this.previousPanelId) { if (this.previousTerminalInstance) { this.terminalService.setActiveInstance(this.previousTerminalInstance); diff --git a/src/vs/workbench/contrib/tasks/common/taskSystem.ts b/src/vs/workbench/contrib/tasks/common/taskSystem.ts index 887c3f288bf..c6d2c0bc03e 100644 --- a/src/vs/workbench/contrib/tasks/common/taskSystem.ts +++ b/src/vs/workbench/contrib/tasks/common/taskSystem.ts @@ -139,4 +139,5 @@ export interface ITaskSystem { terminateAll(): Promise; revealTask(task: Task): boolean; customExecutionComplete(task: Task, result: number): Promise; + isTaskVisible(task: Task): boolean; } diff --git a/src/vs/workbench/contrib/tasks/node/processTaskSystem.ts b/src/vs/workbench/contrib/tasks/node/processTaskSystem.ts index 648fa8617f9..73d947db159 100644 --- a/src/vs/workbench/contrib/tasks/node/processTaskSystem.ts +++ b/src/vs/workbench/contrib/tasks/node/processTaskSystem.ts @@ -82,6 +82,10 @@ export class ProcessTaskSystem implements ITaskSystem { return !!this.childProcess; } + public isTaskVisible(): boolean { + return true; + } + public getActiveTasks(): Task[] { let result: Task[] = []; if (this.activeTask) {