diff --git a/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts b/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts index 820c2bce781..5af608b4ece 100644 --- a/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts +++ b/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts @@ -229,6 +229,8 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer private _onDidChangeTaskSystemInfo: Emitter = new Emitter(); private _willRestart: boolean = false; public onDidChangeTaskSystemInfo: Event = this._onDidChangeTaskSystemInfo.event; + private _onDidReconnectToTasks: Emitter = new Emitter(); + public onDidReconnectToTasks: Event = this._onDidReconnectToTasks.event; constructor( @IConfigurationService private readonly _configurationService: IConfigurationService, @@ -384,6 +386,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer } this.getWorkspaceTasks(TaskRunSource.Reconnect).then(async () => { this._tasksReconnected = await this._reconnectTasks(); + this._onDidReconnectToTasks.fire(); }); } @@ -1862,6 +1865,11 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer } if (executeResult.kind === TaskExecuteKind.Active) { const active = executeResult.active; + if (active && active.same && runSource === TaskRunSource.FolderOpen) { + // ignore, the task is already active, likely from being reconnected. + this._logService.debug('Ignoring task that is already active', executeResult.task); + return executeResult.promise; + } if (active && active.same) { if (this._taskSystem?.isTaskVisible(executeResult.task)) { const message = nls.localize('TaskSystem.activeSame.noBackground', 'The task \'{0}\' is already active.', executeResult.task.getQualifiedLabel()); diff --git a/src/vs/workbench/contrib/tasks/browser/runAutomaticTasks.ts b/src/vs/workbench/contrib/tasks/browser/runAutomaticTasks.ts index 0aaa08a838d..55ec14e22a0 100644 --- a/src/vs/workbench/contrib/tasks/browser/runAutomaticTasks.ts +++ b/src/vs/workbench/contrib/tasks/browser/runAutomaticTasks.ts @@ -28,9 +28,11 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut @IWorkspaceTrustManagementService private readonly _workspaceTrustManagementService: IWorkspaceTrustManagementService, @ILogService private readonly _logService: ILogService) { super(); - if (this._workspaceTrustManagementService.isWorkspaceTrusted()) { - this._tryRunTasks(); - } + this._taskService.onDidReconnectToTasks((() => { + if (this._workspaceTrustManagementService.isWorkspaceTrusted()) { + this._tryRunTasks(); + } + })); this._register(this._workspaceTrustManagementService.onDidChangeTrust(async trusted => { if (trusted) { await this._tryRunTasks(); diff --git a/src/vs/workbench/contrib/tasks/common/taskService.ts b/src/vs/workbench/contrib/tasks/common/taskService.ts index 42236fee046..c96cba1125d 100644 --- a/src/vs/workbench/contrib/tasks/common/taskService.ts +++ b/src/vs/workbench/contrib/tasks/common/taskService.ts @@ -64,6 +64,7 @@ export interface IWorkspaceFolderTaskResult extends IWorkspaceTaskResult { export interface ITaskService { readonly _serviceBrand: undefined; onDidStateChange: Event; + onDidReconnectToTasks: Event; supportsMultipleTaskExecutions: boolean; configureAction(): Action;