提交 37319680 编写于 作者: D Dirk Baeumer

Incooperated API review for tasks

上级 1637f08c
......@@ -334,6 +334,48 @@ declare module 'vscode' {
//#region Tasks
/**
* An object representing an executed Task. It can be used
* to terminate a task.
*
* This interface is not intended to be implemented.
*/
export interface TaskExecution {
/**
* The task that got started.
*/
task: Task;
/**
* Terminates the task execution.
*/
terminate(): void;
}
/**
* An event signaling the start of a task execution.
*
* This interface is not intended to be implemented.
*/
interface TaskStartEvent {
/**
* The task item representing the task that got started.
*/
execution: TaskExecution;
}
/**
* An event signaling the end of an executed task.
*
* This interface is not intended to be implemented.
*/
interface TaskEndEvent {
/**
* The task item representing the task that finished.
*/
execution: TaskExecution;
}
/**
* An event signaling the start of a process execution
* triggered through a task
......@@ -368,76 +410,69 @@ declare module 'vscode' {
exitCode: number;
}
/**
* An object representing an executed Task. It can be used
* to terminate a task.
*
* This interface is not intended to be implemented.
*/
export interface TaskExecution {
export interface TaskFilter {
/**
* The task that got started.
* The task version as used in the tasks.json file.
* The string support the package.json semver notation.
*/
task: Task;
version?: string;
/**
* Fires when the underlying process has been started.
* This event might not fire for tasks that don't
* execute an underlying process.
* The task type to return;
*/
onDidStartProcess: Event<TaskProcessStartEvent>;
type?: string;
}
/**
* Fires when the underlying process has ended.
* This event might not fire for tasks that don't
* execute an underlying process.
*/
onDidEndProcess: Event<TaskProcessEndEvent>;
export namespace workspace {
/**
* Terminates the task execution.
* Fetches all tasks available in the systems. This includes tasks
* from `tasks.json` files as well as tasks from task providers
* contributed through extensions.
*
* @param filter a filter to filter the return tasks.
*/
terminate(): void;
}
export function fetchTasks(filter?: TaskFilter): Thenable<Task[]>;
/**
* An event signaling the start of a task execution.
*
* This interface is not intended to be implemented.
*/
interface TaskStartEvent {
/**
* The task item representing the task that got started.
* Executes a task that is managed by VS Code. The returned
* task execution can be used to terminate the task.
*
* @param task the task to execute
*/
execution: TaskExecution;
}
export function executeTask(task: Task): Thenable<TaskExecution>;
/**
* An event signaling the end of an executed task.
*
* This interface is not intended to be implemented.
*/
interface TaskEndEvent {
/**
* The task item representing the task that finished.
* The currently active task executions or an empty array.
*
* @readonly
*/
execution: TaskExecution;
}
export let taskExecutions: ReadonlyArray<TaskExecution>;
export interface TaskFilter {
/**
* The task version as used in the tasks.json file.
* The string support the package.json semver notation.
* Fires when a task starts.
*/
version?: string;
export const onDidStartTask: Event<TaskStartEvent>;
/**
* The task type to return;
* Fires when a task ends.
*/
type?: string;
export const onDidEndTask: Event<TaskEndEvent>;
}
export namespace workspace {
/**
* Namespace for tasks functionality.
*/
export namespace tasks {
/**
* Register a task provider.
*
* @param type The task kind type this provider is registered for.
* @param provider A task provider.
* @return A [disposable](#Disposable) that unregisters this provider when being disposed.
*/
export function registerTaskProvider(type: string, provider: TaskProvider): Disposable;
/**
* Fetches all tasks available in the systems. This includes tasks
......@@ -472,6 +507,20 @@ declare module 'vscode' {
* Fires when a task ends.
*/
export const onDidEndTask: Event<TaskEndEvent>;
/**
* Fires when the underlying process has been started.
* This event will not fire for tasks that don't
* execute an underlying process.
*/
export const onDidStartTaskProcess: Event<TaskProcessStartEvent>;
/**
* Fires when the underlying process has ended.
* This event will not fire for tasks that don't
* execute an underlying process.
*/
export const onDidEndTaskProcess: Event<TaskProcessEndEvent>;
}
//#endregion
......
......@@ -621,6 +621,32 @@ export function createApiFactory(
}
};
const tasks: typeof vscode.tasks = {
registerTaskProvider: (type: string, provider: vscode.TaskProvider) => {
return extHostTask.registerTaskProvider(extension, provider);
},
fetchTasks: proposedApiFunction(extension, (filter?: vscode.TaskFilter): Thenable<vscode.Task[]> => {
return extHostTask.fetchTasks(filter);
}),
executeTask: proposedApiFunction(extension, (task: vscode.Task): Thenable<vscode.TaskExecution> => {
return extHostTask.executeTask(extension, task);
}),
get taskExecutions(): vscode.TaskExecution[] {
return extHostTask.taskExecutions;
},
onDidStartTask: (listeners, thisArgs?, disposables?) => {
return extHostTask.onDidStartTask(listeners, thisArgs, disposables);
},
onDidEndTask: (listeners, thisArgs?, disposables?) => {
return extHostTask.onDidEndTask(listeners, thisArgs, disposables);
},
onDidStartTaskProcess: (listeners, thisArgs?, disposables?) => {
return extHostTask.onDidStartTaskProcess(listeners, thisArgs, disposables);
},
onDidEndTaskProcess: (listeners, thisArgs?, disposables?) => {
return extHostTask.onDidEndTaskProcess(listeners, thisArgs, disposables);
}
};
return <typeof vscode>{
version: pkg.version,
......@@ -633,6 +659,7 @@ export function createApiFactory(
workspace,
scm,
debug,
tasks,
// types
Breakpoint: extHostTypes.Breakpoint,
CancellationTokenSource: CancellationTokenSource,
......
......@@ -690,9 +690,6 @@ namespace TaskFilterDTO {
class TaskExecutionImpl implements vscode.TaskExecution {
private readonly _onDidTaskProcessStarted: Emitter<vscode.TaskProcessStartEvent> = new Emitter<vscode.TaskProcessStartEvent>();
private readonly _onDidTaskProcessEnded: Emitter<vscode.TaskProcessEndEvent> = new Emitter<vscode.TaskProcessEndEvent>();
constructor(private readonly _tasks: ExtHostTask, readonly _id: string, private readonly _task: vscode.Task) {
}
......@@ -704,26 +701,10 @@ class TaskExecutionImpl implements vscode.TaskExecution {
this._tasks.terminateTask(this);
}
public get onDidStartProcess(): Event<vscode.TaskProcessStartEvent> {
return this._onDidTaskProcessStarted.event;
}
public fireDidStartProcess(value: TaskProcessStartedDTO): void {
this._onDidTaskProcessStarted.fire({
execution: this,
processId: value.processId
});
}
public get onDidEndProcess(): Event<vscode.TaskProcessEndEvent> {
return this._onDidTaskProcessEnded.event;
}
public fireDidEndProcess(value: TaskProcessEndedDTO): void {
this._onDidTaskProcessEnded.fire({
execution: this,
exitCode: value.exitCode
});
}
}
......@@ -755,6 +736,9 @@ export class ExtHostTask implements ExtHostTaskShape {
private readonly _onDidExecuteTask: Emitter<vscode.TaskStartEvent> = new Emitter<vscode.TaskStartEvent>();
private readonly _onDidTerminateTask: Emitter<vscode.TaskEndEvent> = new Emitter<vscode.TaskEndEvent>();
private readonly _onDidTaskProcessStarted: Emitter<vscode.TaskProcessStartEvent> = new Emitter<vscode.TaskProcessStartEvent>();
private readonly _onDidTaskProcessEnded: Emitter<vscode.TaskProcessEndEvent> = new Emitter<vscode.TaskProcessEndEvent>();
constructor(mainContext: IMainContext, extHostWorkspace: ExtHostWorkspace) {
this._proxy = mainContext.getProxy(MainContext.MainThreadTask);
this._extHostWorkspace = extHostWorkspace;
......@@ -807,36 +791,12 @@ export class ExtHostTask implements ExtHostTaskShape {
}
}
public $onDidStartTask(execution: TaskExecutionDTO): void {
this._onDidExecuteTask.fire({
execution: this.getTaskExecution(execution)
});
}
public $onDidStartTaskProcess(value: TaskProcessStartedDTO): void {
const execution = this.getTaskExecution(value.id);
if (execution) {
execution.fireDidStartProcess(value);
}
}
public $onDidEndTaskProcess(value: TaskProcessEndedDTO): void {
const execution = this.getTaskExecution(value.id);
if (execution) {
execution.fireDidEndProcess(value);
}
}
get taskExecutions(): vscode.TaskExecution[] {
public get taskExecutions(): vscode.TaskExecution[] {
let result: vscode.TaskExecution[] = [];
this._taskExecutions.forEach(value => result.push(value));
return result;
}
get onDidStartTask(): Event<vscode.TaskStartEvent> {
return this._onDidExecuteTask.event;
}
public terminateTask(execution: vscode.TaskExecution): TPromise<void> {
if (!(execution instanceof TaskExecutionImpl)) {
throw new Error('No valid task execution provided');
......@@ -844,6 +804,20 @@ export class ExtHostTask implements ExtHostTaskShape {
return this._proxy.$terminateTask((execution as TaskExecutionImpl)._id);
}
public get onDidStartTask(): Event<vscode.TaskStartEvent> {
return this._onDidExecuteTask.event;
}
public $onDidStartTask(execution: TaskExecutionDTO): void {
this._onDidExecuteTask.fire({
execution: this.getTaskExecution(execution)
});
}
public get onDidEndTask(): Event<vscode.TaskEndEvent> {
return this._onDidTerminateTask.event;
}
public $OnDidEndTask(execution: TaskExecutionDTO): void {
const _execution = this.getTaskExecution(execution);
this._taskExecutions.delete(execution.id);
......@@ -852,8 +826,32 @@ export class ExtHostTask implements ExtHostTaskShape {
});
}
get onDidEndTask(): Event<vscode.TaskEndEvent> {
return this._onDidTerminateTask.event;
public get onDidStartTaskProcess(): Event<vscode.TaskProcessStartEvent> {
return this._onDidTaskProcessStarted.event;
}
public $onDidStartTaskProcess(value: TaskProcessStartedDTO): void {
const execution = this.getTaskExecution(value.id);
if (execution) {
this._onDidTaskProcessStarted.fire({
execution: execution,
processId: value.processId
});
}
}
public get onDidEndTaskProcess(): Event<vscode.TaskProcessEndEvent> {
return this._onDidTaskProcessEnded.event;
}
public $onDidEndTaskProcess(value: TaskProcessEndedDTO): void {
const execution = this.getTaskExecution(value.id);
if (execution) {
this._onDidTaskProcessEnded.fire({
execution: execution,
exitCode: value.exitCode
});
}
}
public $provideTasks(handle: number): TPromise<TaskSystem.TaskSet> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册