From 6fe6269c41bf555073cc2a0024709f6e76eb6dca Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Tue, 17 Sep 2019 17:27:15 +0200 Subject: [PATCH] Keep better track of custom executions for reruns and depends Fixes #80964 --- src/vs/workbench/api/common/extHostTask.ts | 36 ++++++++++++++-------- src/vs/workbench/api/node/extHostTask.ts | 4 +-- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/vs/workbench/api/common/extHostTask.ts b/src/vs/workbench/api/common/extHostTask.ts index a2119063d3d65..7667465f6bd41 100644 --- a/src/vs/workbench/api/common/extHostTask.ts +++ b/src/vs/workbench/api/common/extHostTask.ts @@ -374,8 +374,9 @@ export abstract class ExtHostTaskBase implements ExtHostTaskShape { protected _handlers: Map; protected _taskExecutions: Map; protected _providedCustomExecutions2: Map; + private _notProvidedCustomExecutions: Set; // Used for custom executions tasks that are created and run through executeTask. protected _activeCustomExecutions2: Map; - + private _lastStartedTask: string | undefined; protected readonly _onDidExecuteTask: Emitter = new Emitter(); protected readonly _onDidTerminateTask: Emitter = new Emitter(); @@ -399,6 +400,7 @@ export abstract class ExtHostTaskBase implements ExtHostTaskShape { this._handlers = new Map(); this._taskExecutions = new Map(); this._providedCustomExecutions2 = new Map(); + this._notProvidedCustomExecutions = new Set(); this._activeCustomExecutions2 = new Map(); } @@ -462,6 +464,7 @@ export abstract class ExtHostTaskBase implements ExtHostTaskShape { this._activeCustomExecutions2.set(execution.id, execution2); this._terminalService.attachPtyToTerminal(terminalId, await execution2.callback()); } + this._lastStartedTask = execution.id; this._onDidExecuteTask.fire({ execution: await this.getTaskExecution(execution) @@ -571,7 +574,7 @@ export abstract class ExtHostTaskBase implements ExtHostTaskShape { } if (CustomExecution2DTO.is(resolvedTaskDTO.execution)) { - await this.addCustomExecution2(resolvedTaskDTO, resolvedTask); + await this.addCustomExecution2(resolvedTaskDTO, resolvedTask, true); } return await this.resolveTaskInternal(resolvedTaskDTO); @@ -585,8 +588,11 @@ export abstract class ExtHostTaskBase implements ExtHostTaskShape { return this._handleCounter++; } - protected async addCustomExecution2(taskDTO: tasks.TaskDTO, task: vscode.Task2): Promise { + protected async addCustomExecution2(taskDTO: tasks.TaskDTO, task: vscode.Task2, isProvided: boolean): Promise { const taskId = await this._proxy.$createTaskId(taskDTO); + if (!isProvided && !this._providedCustomExecutions2.has(taskId)) { + this._notProvidedCustomExecutions.add(taskId); + } this._providedCustomExecutions2.set(taskId, (task).execution2); } @@ -618,16 +624,22 @@ export abstract class ExtHostTaskBase implements ExtHostTaskShape { this._activeCustomExecutions2.delete(execution.id); } - const lastCustomExecution = this._providedCustomExecutions2.get(execution.id); // Technically we don't really need to do this, however, if an extension // is executing a task through "executeTask" over and over again - // with different properties in the task definition, then this list + // with different properties in the task definition, then the map of executions // could grow indefinitely, something we don't want. - this._providedCustomExecutions2.clear(); - // We do still need to hang on to the last custom execution so that the - // Rerun Task command doesn't choke when it tries to rerun a custom execution - if (lastCustomExecution) { - this._providedCustomExecutions2.set(execution.id, lastCustomExecution); + if (this._notProvidedCustomExecutions.has(execution.id) && (this._lastStartedTask !== execution.id)) { + this._providedCustomExecutions2.delete(execution.id); + this._notProvidedCustomExecutions.delete(execution.id); + } + let iterator = this._notProvidedCustomExecutions.values(); + let iteratorResult = iterator.next(); + while (!iteratorResult.done) { + if (!this._activeCustomExecutions2.has(iteratorResult.value) && (this._lastStartedTask !== iteratorResult.value)) { + this._providedCustomExecutions2.delete(iteratorResult.value); + this._notProvidedCustomExecutions.delete(iteratorResult.value); + } + iteratorResult = iterator.next(); } } @@ -663,7 +675,7 @@ export class WorkerExtHostTask extends ExtHostTaskBase { // in the provided custom execution map that is cleaned up after the // task is executed. if (CustomExecution2DTO.is(dto.execution)) { - await this.addCustomExecution2(dto, task); + await this.addCustomExecution2(dto, task, false); } else { throw new Error('Not implemented'); } @@ -685,7 +697,7 @@ export class WorkerExtHostTask extends ExtHostTaskBase { // The ID is calculated on the main thread task side, so, let's call into it here. // We need the task id's pre-computed for custom task executions because when OnDidStartTask // is invoked, we have to be able to map it back to our data. - taskIdPromises.push(this.addCustomExecution2(taskDTO, task)); + taskIdPromises.push(this.addCustomExecution2(taskDTO, task, true)); } else { console.warn('Only custom execution tasks supported.'); } diff --git a/src/vs/workbench/api/node/extHostTask.ts b/src/vs/workbench/api/node/extHostTask.ts index f1379251ab1a2..71d8b818b72cc 100644 --- a/src/vs/workbench/api/node/extHostTask.ts +++ b/src/vs/workbench/api/node/extHostTask.ts @@ -57,7 +57,7 @@ export class ExtHostTask extends ExtHostTaskBase { // in the provided custom execution map that is cleaned up after the // task is executed. if (CustomExecution2DTO.is(dto.execution)) { - await this.addCustomExecution2(dto, task); + await this.addCustomExecution2(dto, task, false); } return this._proxy.$executeTask(dto).then(value => this.getTaskExecution(value, task)); @@ -80,7 +80,7 @@ export class ExtHostTask extends ExtHostTaskBase { // The ID is calculated on the main thread task side, so, let's call into it here. // We need the task id's pre-computed for custom task executions because when OnDidStartTask // is invoked, we have to be able to map it back to our data. - taskIdPromises.push(this.addCustomExecution2(taskDTO, task)); + taskIdPromises.push(this.addCustomExecution2(taskDTO, task, true)); } } }