Task query and execution polish

This commit is contained in:
Dirk Baeumer
2018-03-26 17:04:31 +02:00
parent e45a276a07
commit 6577bde536
8 changed files with 121 additions and 36 deletions

View File

@@ -613,6 +613,7 @@ namespace TaskDTO {
if (!execution || !definition || !scope) {
return undefined;
}
let group = (value.group as types.TaskGroup) ? (value.group as types.TaskGroup).id : undefined;
let result: TaskDTO = {
_id: (value as types.Task)._id,
definition,
@@ -624,7 +625,7 @@ namespace TaskDTO {
},
execution,
isBackground: value.isBackground,
group: (value.group as types.TaskGroup).id,
group: group,
presentationOptions: TaskPresentationOptionsDTO.from(value.presentationOptions),
problemMatchers: value.problemMatchers,
hasDefinedMatchers: (value as types.Task).hasDefinedMatchers
@@ -675,17 +676,26 @@ namespace TaskDTO {
}
class TaskExecutionImpl implements vscode.TaskExecution {
constructor(readonly _id: string) {
constructor(readonly _id: string, private readonly _task: vscode.Task, private readonly _tasks: ExtHostTask) {
}
get task(): vscode.Task {
return this._task;
}
public terminate(): void {
this._tasks.terminateTask(this);
}
}
namespace TaskExecutionDTO {
export function to(value: TaskExecutionDTO): vscode.TaskExecution {
return new TaskExecutionImpl(value.id);
export function to(value: TaskExecutionDTO, tasks: ExtHostTask): vscode.TaskExecution {
return new TaskExecutionImpl(value.id, TaskDTO.to(value.task, tasks.extHostWorkspace), tasks);
}
export function from(value: vscode.TaskExecution): TaskExecutionDTO {
return {
id: (value as TaskExecutionImpl)._id
id: (value as TaskExecutionImpl)._id,
task: undefined
};
}
}
@@ -712,6 +722,10 @@ export class ExtHostTask implements ExtHostTaskShape {
this._handlers = new Map<number, HandlerData>();
}
public get extHostWorkspace(): ExtHostWorkspace {
return this._extHostWorkspace;
}
public registerTaskProvider(extension: IExtensionDescription, provider: vscode.TaskProvider): vscode.Disposable {
if (!provider) {
return new types.Disposable(() => { });
@@ -742,15 +756,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 => TaskExecutionDTO.to(value));
return this._proxy.$executeTask(TaskHandleDTO.from(tTask)).then(value => new TaskExecutionImpl(value.id, task, this));
} else {
return this._proxy.$executeTask(TaskDTO.from(task, extension)).then(value => TaskExecutionDTO.to(value));
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));
}
}
public $taskStarted(execution: TaskExecutionDTO): void {
this._onDidExecuteTask.fire({
execution: TaskExecutionDTO.to(execution)
execution: TaskExecutionDTO.to(execution, this)
});
}
@@ -762,12 +780,12 @@ export class ExtHostTask implements ExtHostTaskShape {
if (!(execution instanceof TaskExecutionImpl)) {
throw new Error('No valid task execution provided');
}
return this._proxy.$terminateTask(TaskExecutionDTO.from(execution));
return this._proxy.$terminateTask((execution as TaskExecutionImpl)._id);
}
public $taskEnded(execution: TaskExecutionDTO): void {
this._onDidTerminateTask.fire({
execution: TaskExecutionDTO.to(execution)
execution: TaskExecutionDTO.to(execution, this)
});
}