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 18, 2019
1 parent 4572886 commit c094b1c
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- [cpp] added new `cpp.clangdExecutable` and `cpp.clangdArgs` to customize language server start command.
- [monaco] Fix document-saving that was taking too long.
- [plug-in] added `tasks.onDidStartTask` Plug-in API
- [plug-in] added `tasks.onDidEndTask` Plug-in API
- Enabled INI syntax highlighting for `.properties` and `.toml` files
- [security] update xterm.js to 3.9.2

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 @@ -1028,6 +1028,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 @@ -582,6 +582,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 @@ -7001,6 +7001,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 @@ -7014,6 +7026,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 c094b1c

Please sign in to comment.