Skip to content

Commit 019e959

Browse files
authored
Merge pull request microsoft#200872 from jeanp413/fix-194618
Fix vscode.tasks.executeTask error Unexpected: Task does not exist after task.terminate()
2 parents 1edd865 + 1ff0d63 commit 019e959

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

src/vs/workbench/api/common/extHostTask.ts

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,11 @@ export abstract class ExtHostTaskBase implements ExtHostTaskShape, IExtHostTask
501501
}
502502

503503
public async $OnDidEndTask(execution: tasks.ITaskExecutionDTO): Promise<void> {
504+
if (!this._taskExecutionPromises.has(execution.id)) {
505+
// Event already fired by the main thread
506+
// See https://github.com/microsoft/vscode/commit/aaf73920aeae171096d205efb2c58804a32b6846
507+
return;
508+
}
504509
const _execution = await this.getTaskExecution(execution);
505510
this._taskExecutionPromises.delete(execution.id);
506511
this._taskExecutions.delete(execution.id);
@@ -633,29 +638,22 @@ export abstract class ExtHostTaskBase implements ExtHostTaskShape, IExtHostTask
633638
if (result) {
634639
return result;
635640
}
636-
const createdResult: Promise<TaskExecutionImpl> = new Promise((resolve, reject) => {
637-
function resolvePromiseWithCreatedTask(that: ExtHostTaskBase, execution: tasks.ITaskExecutionDTO, taskToCreate: vscode.Task | types.Task | undefined) {
638-
if (!taskToCreate) {
639-
reject('Unexpected: Task does not exist.');
640-
} else {
641-
resolve(new TaskExecutionImpl(that, execution.id, taskToCreate));
642-
}
643-
}
644641

645-
if (task) {
646-
resolvePromiseWithCreatedTask(this, execution, task);
647-
} else {
648-
TaskDTO.to(execution.task, this._workspaceProvider, this._providedCustomExecutions2)
649-
.then(task => resolvePromiseWithCreatedTask(this, execution, task));
650-
}
651-
});
652-
653-
this._taskExecutionPromises.set(execution.id, createdResult);
654-
return createdResult.then(executionCreatedResult => {
655-
this._taskExecutions.set(execution.id, executionCreatedResult);
656-
return executionCreatedResult;
657-
}, rejected => {
658-
return Promise.reject(rejected);
642+
let executionPromise: Promise<TaskExecutionImpl>;
643+
if (!task) {
644+
executionPromise = TaskDTO.to(execution.task, this._workspaceProvider, this._providedCustomExecutions2).then(t => {
645+
if (!t) {
646+
throw new ErrorNoTelemetry('Unexpected: Task does not exist.');
647+
}
648+
return new TaskExecutionImpl(this, execution.id, t);
649+
});
650+
} else {
651+
executionPromise = Promise.resolve(new TaskExecutionImpl(this, execution.id, task));
652+
}
653+
this._taskExecutionPromises.set(execution.id, executionPromise);
654+
return executionPromise.then(taskExecution => {
655+
this._taskExecutions.set(execution.id, taskExecution);
656+
return taskExecution;
659657
});
660658
}
661659

0 commit comments

Comments
 (0)