提交 825d5f3f 编写于 作者: D Dirk Baeumer

Fixes #47465: Provide a method of matching TaskExecution objects

上级 cfb26b3d
......@@ -711,6 +711,7 @@ export class ExtHostTask implements ExtHostTaskShape {
private _extHostWorkspace: ExtHostWorkspace;
private _handleCounter: number;
private _handlers: Map<number, HandlerData>;
private _taskExecutions: Map<string, TaskExecutionImpl>;
private readonly _onDidExecuteTask: Emitter<vscode.TaskStartEvent> = new Emitter<vscode.TaskStartEvent>();
private readonly _onDidTerminateTask: Emitter<vscode.TaskEndEvent> = new Emitter<vscode.TaskEndEvent>();
......@@ -720,6 +721,7 @@ export class ExtHostTask implements ExtHostTaskShape {
this._extHostWorkspace = extHostWorkspace;
this._handleCounter = 0;
this._handlers = new Map<number, HandlerData>();
this._taskExecutions = new Map<string, TaskExecutionImpl>();
}
public get extHostWorkspace(): ExtHostWorkspace {
......@@ -756,19 +758,19 @@ export class ExtHostTask implements ExtHostTaskShape {
let tTask = (task as types.Task);
// We have a preserved ID. So the task didn't change.
if (tTask._id !== void 0) {
return this._proxy.$executeTask(TaskHandleDTO.from(tTask)).then(value => new TaskExecutionImpl(value.id, task, this));
return this._proxy.$executeTask(TaskHandleDTO.from(tTask)).then(value => this.getTaskExecution(value, task));
} else {
let dto = TaskDTO.from(task, extension);
if (dto === void 0) {
return Promise.reject(new Error('Task is not valid'));
}
return this._proxy.$executeTask(dto).then(value => new TaskExecutionImpl(value.id, task, this));
return this._proxy.$executeTask(dto).then(value => this.getTaskExecution(value, task));
}
}
public $taskStarted(execution: TaskExecutionDTO): void {
this._onDidExecuteTask.fire({
execution: TaskExecutionDTO.to(execution, this)
execution: this.getTaskExecution(execution)
});
}
......@@ -784,8 +786,10 @@ export class ExtHostTask implements ExtHostTaskShape {
}
public $taskEnded(execution: TaskExecutionDTO): void {
const _execution = this.getTaskExecution(execution);
this._taskExecutions.delete(execution.id);
this._onDidTerminateTask.fire({
execution: TaskExecutionDTO.to(execution, this)
execution: _execution
});
}
......@@ -810,4 +814,14 @@ export class ExtHostTask implements ExtHostTaskShape {
private nextHandle(): number {
return this._handleCounter++;
}
private getTaskExecution(execution: TaskExecutionDTO, task?: vscode.Task): TaskExecutionImpl {
let result: TaskExecutionImpl = this._taskExecutions.get(execution.id);
if (result) {
return result;
}
result = new TaskExecutionImpl(execution.id, task ? task : TaskDTO.to(execution.task, this._extHostWorkspace), this);
this._taskExecutions.set(execution.id, result);
return result;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册