Skip to content

Commit

Permalink
Add 'tasks.onDidEndTask' Plug-in API
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Nikitenko <rnikiten@redhat.com>
  • Loading branch information
RomanNikitenko committed Jan 23, 2019
1 parent 74f6091 commit f143065
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## v0.3.20
- [plugin] added `tasks.onDidEndTask` Plug-in API


## v0.3.19
- [core] added `hostname` alias
- [core] added new `editor.formatOnSave` preference, to format documents on manual save
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-ext/src/api/plugin-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,7 @@ export interface TasksExt {
$provideTasks(handle: number): Promise<TaskDto[] | undefined>;
$resolveTask(handle: number, task: TaskDto): Promise<TaskDto | undefined>;
$onDidStartTask(execution: TaskExecutionDto): void;
$onDidEndTask(id: number): void;
}

export interface TasksMain {
Expand Down
8 changes: 7 additions & 1 deletion packages/plugin-ext/src/main/browser/tasks-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { DisposableCollection } from '@theia/core';
import { TaskProviderRegistry, TaskResolverRegistry, TaskProvider, TaskResolver } from '@theia/task/lib/browser/task-contribution';
import { interfaces } from 'inversify';
import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
import { TaskInfo } from '@theia/task/lib/common/task-protocol';
import { TaskInfo, TaskExitedEvent } from '@theia/task/lib/common/task-protocol';
import { TaskWatcher } from '@theia/task/lib/common/task-watcher';
import { TaskService } from '@theia/task/lib/browser/task-service';
import { TaskConfiguration } from '@theia/task/lib/common';
Expand Down Expand Up @@ -63,6 +63,12 @@ export class TasksMainImpl implements TasksMain {
});
}
});

this.taskWatcher.onTaskExit((event: TaskExitedEvent) => {
if (event.ctx === this.workspaceRootUri) {
this.proxy.$onDidEndTask(event.taskId);
}
});
}

$registerTaskProvider(handle: number, type: string): void {
Expand Down
4 changes: 4 additions & 0 deletions packages/plugin-ext/src/plugin/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,10 @@ export function createAPIFactory(

onDidStartTask(listener, thisArg?, disposables?) {
return tasksExt.onDidStartTask(listener, thisArg, disposables);
},

onDidEndTask(listener, thisArg?, disposables?) {
return tasksExt.onDidEndTask(listener, thisArg, disposables);
}
};

Expand Down
18 changes: 18 additions & 0 deletions packages/plugin-ext/src/plugin/tasks/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class TasksExtImpl implements TasksExt {
private taskExecutions = new Map<number, theia.TaskExecution>();

private readonly onDidExecuteTask: Emitter<theia.TaskStartEvent> = new Emitter<theia.TaskStartEvent>();
private readonly onDidTerminateTask: Emitter<theia.TaskEndEvent> = new Emitter<theia.TaskEndEvent>();

constructor(rpc: RPCProtocol) {
this.proxy = rpc.getProxy(PLUGIN_RPC_CONTEXT.TASKS_MAIN);
Expand All @@ -51,6 +52,23 @@ export class TasksExtImpl implements TasksExt {
});
}

get onDidEndTask(): Event<theia.TaskEndEvent> {
return this.onDidTerminateTask.event;
}

$onDidEndTask(id: number): void {
const taskExecution = this.taskExecutions.get(id);
if (!taskExecution) {
throw new Error(`Task execution with id ${id} is not found`);
}

this.taskExecutions.delete(id);

this.onDidTerminateTask.fire({
execution: taskExecution
});
}

registerTaskProvider(type: string, provider: theia.TaskProvider): theia.Disposable {
const callId = this.addNewAdapter(new TaskProviderAdapter(provider));
this.proxy.$registerTaskProvider(callId, type);
Expand Down
15 changes: 15 additions & 0 deletions packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7021,6 +7021,18 @@ declare module '@theia/plugin' {
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;
}

export namespace tasks {

/**
Expand All @@ -7034,6 +7046,9 @@ declare module '@theia/plugin' {

/** Fires when a task starts. */
export const onDidStartTask: Event<TaskStartEvent>;

/** Fires when a task ends. */
export const onDidEndTask: Event<TaskEndEvent>;
}

/**
Expand Down

0 comments on commit f143065

Please sign in to comment.