Skip to content

Commit

Permalink
Stabilize CustomExecution task API
Browse files Browse the repository at this point in the history
Fixes #80375
  • Loading branch information
alexr00 committed Oct 22, 2019
1 parent 9670193 commit 030af95
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 54 deletions.
20 changes: 18 additions & 2 deletions src/vs/vscode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5241,6 +5241,22 @@ declare module 'vscode' {
options?: ShellExecutionOptions;
}

/**
* Class used to execute an extension callback as a task.
*/
export class CustomExecution {
/**
* Constructs a CustomExecution task object. The callback will be executed the task is run, at which point the
* extension should return the Pseudoterminal it will "run in". The task should wait to do further execution until
* [Pseudoterminal.open](#Pseudoterminal.open) is called. Task cancellation should be handled using
* [Pseudoterminal.close](#Pseudoterminal.close). When the task is complete fire
* [Pseudoterminal.onDidClose](#Pseudoterminal.onDidClose).
* @param process The [Pseudoterminal](#Pseudoterminal) to be used by the task to display output.
* @param callback The callback that will be called when the task is started by a user.
*/
constructor(callback: () => Thenable<Pseudoterminal>);
}

/**
* The scope of a task.
*/
Expand Down Expand Up @@ -5283,7 +5299,7 @@ declare module 'vscode' {
* or '$eslint'. Problem matchers can be contributed by an extension using
* the `problemMatchers` extension point.
*/
constructor(taskDefinition: TaskDefinition, scope: WorkspaceFolder | TaskScope.Global | TaskScope.Workspace, name: string, source: string, execution?: ProcessExecution | ShellExecution, problemMatchers?: string | string[]);
constructor(taskDefinition: TaskDefinition, scope: WorkspaceFolder | TaskScope.Global | TaskScope.Workspace, name: string, source: string, execution?: ProcessExecution | ShellExecution | CustomExecution, problemMatchers?: string | string[]);

/**
* ~~Creates a new task.~~
Expand Down Expand Up @@ -5318,7 +5334,7 @@ declare module 'vscode' {
/**
* The task's execution engine
*/
execution?: ProcessExecution | ShellExecution;
execution?: ProcessExecution | ShellExecution | CustomExecution;

/**
* Whether the task is a background task or not.
Expand Down
35 changes: 1 addition & 34 deletions src/vs/vscode.proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -895,45 +895,12 @@ declare module 'vscode' {
//#endregion

//#region CustomExecution
/**
* Class used to execute an extension callback as a task.
*/
export class CustomExecution {
/**
* Constructs a CustomExecution task object. The callback will be executed the task is run, at which point the
* extension should return the Pseudoterminal it will "run in". The task should wait to do further execution until
* [Pseudoterminal.open](#Pseudoterminal.open) is called. Task cancellation should be handled using
* [Pseudoterminal.close](#Pseudoterminal.close). When the task is complete fire
* [Pseudoterminal.onDidClose](#Pseudoterminal.onDidClose).
* @param process The [Pseudoterminal](#Pseudoterminal) to be used by the task to display output.
* @param callback The callback that will be called when the task is started by a user.
*/
constructor(callback: () => Thenable<Pseudoterminal>);
}


/**
* A task to execute
*/
export class Task2 extends Task {
/**
* Creates a new task.
*
* @param definition The task definition as defined in the taskDefinitions extension point.
* @param scope Specifies the task's scope. It is either a global or a workspace task or a task for a specific workspace folder.
* @param name The task's name. Is presented in the user interface.
* @param source The task's source (e.g. 'gulp', 'npm', ...). Is presented in the user interface.
* @param execution The process or shell execution.
* @param problemMatchers the names of problem matchers to use, like '$tsc'
* or '$eslint'. Problem matchers can be contributed by an extension using
* the `problemMatchers` extension point.
*/
constructor(taskDefinition: TaskDefinition, scope: WorkspaceFolder | TaskScope.Global | TaskScope.Workspace, name: string, source: string, execution?: ProcessExecution | ShellExecution | CustomExecution, problemMatchers?: string | string[]);

/**
* The task's execution engine
*/
execution2?: ProcessExecution | ShellExecution | CustomExecution;

detail?: string;
}

Expand Down
14 changes: 7 additions & 7 deletions src/vs/workbench/api/common/extHostTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ export namespace TaskDTO {
execution = ProcessExecutionDTO.from(value.execution);
} else if (value.execution instanceof types.ShellExecution) {
execution = ShellExecutionDTO.from(value.execution);
} else if ((<vscode.Task2>value).execution2 && (<vscode.Task2>value).execution2 instanceof types.CustomExecution) {
execution = CustomExecutionDTO.from(<types.CustomExecution>(<vscode.Task2>value).execution2);
} else if (value.execution && value.execution instanceof types.CustomExecution) {
execution = CustomExecutionDTO.from(<types.CustomExecution>value.execution);
}

const definition: tasks.TaskDefinitionDTO | undefined = TaskDefinitionDTO.from(value.definition);
Expand Down Expand Up @@ -578,7 +578,7 @@ export abstract class ExtHostTaskBase implements ExtHostTaskShape {
}

if (CustomExecutionDTO.is(resolvedTaskDTO.execution)) {
await this.addCustomExecution(resolvedTaskDTO, <vscode.Task2>resolvedTask, true);
await this.addCustomExecution(resolvedTaskDTO, resolvedTask, true);
}

return await this.resolveTaskInternal(resolvedTaskDTO);
Expand All @@ -592,12 +592,12 @@ export abstract class ExtHostTaskBase implements ExtHostTaskShape {
return this._handleCounter++;
}

protected async addCustomExecution(taskDTO: tasks.TaskDTO, task: vscode.Task2, isProvided: boolean): Promise<void> {
protected async addCustomExecution(taskDTO: tasks.TaskDTO, task: vscode.Task, isProvided: boolean): Promise<void> {
const taskId = await this._proxy.$createTaskId(taskDTO);
if (!isProvided && !this._providedCustomExecutions2.has(taskId)) {
this._notProvidedCustomExecutions.add(taskId);
}
this._providedCustomExecutions2.set(taskId, <types.CustomExecution>(<vscode.Task2>task).execution2);
this._providedCustomExecutions2.set(taskId, <types.CustomExecution>task.execution);
}

protected async getTaskExecution(execution: tasks.TaskExecutionDTO | string, task?: vscode.Task): Promise<TaskExecutionImpl> {
Expand Down Expand Up @@ -679,7 +679,7 @@ export class WorkerExtHostTask extends ExtHostTaskBase {
// in the provided custom execution map that is cleaned up after the
// task is executed.
if (CustomExecutionDTO.is(dto.execution)) {
await this.addCustomExecution(dto, <vscode.Task2>task, false);
await this.addCustomExecution(dto, task, false);
} else {
throw new Error('Not implemented');
}
Expand All @@ -701,7 +701,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.addCustomExecution(taskDTO, <vscode.Task2>task, true));
taskIdPromises.push(this.addCustomExecution(taskDTO, task, true));
} else {
console.warn('Only custom execution tasks supported.');
}
Expand Down
12 changes: 2 additions & 10 deletions src/vs/workbench/api/common/extHostTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1929,19 +1929,11 @@ export class Task implements vscode.Task2 {
this._name = value;
}

get execution(): ProcessExecution | ShellExecution | undefined {
return (this._execution instanceof CustomExecution) ? undefined : this._execution;
}

set execution(value: ProcessExecution | ShellExecution | undefined) {
this.execution2 = value;
}

get execution2(): ProcessExecution | ShellExecution | CustomExecution | undefined {
get execution(): ProcessExecution | ShellExecution | CustomExecution | undefined {
return this._execution;
}

set execution2(value: ProcessExecution | ShellExecution | CustomExecution | undefined) {
set execution(value: ProcessExecution | ShellExecution | CustomExecution | undefined) {
if (value === null) {
value = undefined;
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/node/extHostTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (CustomExecutionDTO.is(dto.execution)) {
await this.addCustomExecution(dto, <vscode.Task2>task, false);
await this.addCustomExecution(dto, task, false);
}

return this._proxy.$executeTask(dto).then(value => this.getTaskExecution(value, task));
Expand Down

0 comments on commit 030af95

Please sign in to comment.