Only show 'task already running' message when task is visible

If the task is running but not visible, show it

Fixes #84794
This commit is contained in:
Alex Ross
2020-01-23 15:06:52 +01:00
parent 419360d3ba
commit dd3b65f955
4 changed files with 30 additions and 27 deletions
@@ -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);
}
@@ -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);
@@ -139,4 +139,5 @@ export interface ITaskSystem {
terminateAll(): Promise<TaskTerminateResponse[]>;
revealTask(task: Task): boolean;
customExecutionComplete(task: Task, result: number): Promise<void>;
isTaskVisible(task: Task): boolean;
}
@@ -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) {