Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
  • Loading branch information
Akos Kitta committed Mar 10, 2021
1 parent 5547c25 commit e5939cd
Show file tree
Hide file tree
Showing 9 changed files with 206 additions and 38 deletions.
4 changes: 3 additions & 1 deletion packages/plugin-ext/src/common/plugin-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1664,19 +1664,21 @@ export const MAIN_RPC_CONTEXT = {
export interface TasksExt {
$provideTasks(handle: number, token?: CancellationToken): Promise<TaskDto[] | undefined>;
$resolveTask(handle: number, task: TaskDto, token?: CancellationToken): Promise<TaskDto | undefined>;
$onDidStartTask(execution: TaskExecutionDto): void;
$onDidStartTask(execution: TaskExecutionDto, terminalId: number): void;
$onDidEndTask(id: number): void;
$onDidStartTaskProcess(processId: number | undefined, execution: TaskExecutionDto): void;
$onDidEndTaskProcess(exitCode: number | undefined, taskId: number): void;
}

export interface TasksMain {
$createTaskId(task: TaskDto): Promise<string>;
$registerTaskProvider(handle: number, type: string): void;
$fetchTasks(taskVersion: string | undefined, taskType: string | undefined): Promise<TaskDto[]>;
$executeTask(taskDto: TaskDto): Promise<TaskExecutionDto | undefined>;
$taskExecutions(): Promise<TaskExecutionDto[]>;
$unregister(handle: number): void;
$terminateTask(id: number): void;
$customExecutionComplete(id: string, result?: number): Promise<void>;
}

export interface AuthenticationExt {
Expand Down
16 changes: 15 additions & 1 deletion packages/plugin-ext/src/main/browser/tasks-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class TasksMainImpl implements TasksMain, Disposable {
this.proxy.$onDidStartTask({
id: event.taskId,
task: this.fromTaskConfiguration(event.config)
});
}, event.terminalId!);
}));

this.toDispose.push(this.taskWatcher.onTaskExit((event: TaskExitedEvent) => {
Expand All @@ -80,6 +80,11 @@ export class TasksMainImpl implements TasksMain, Disposable {
this.toDispose.dispose();
}

async $createTaskId(task: TaskDto): Promise<string> {
console.log('$createTaskId', JSON.stringify(task));
return 'foo-bar';
}

$registerTaskProvider(handle: number, type: string): void {
const taskProvider = this.createTaskProvider(handle);
const taskResolver = this.createTaskResolver(handle);
Expand Down Expand Up @@ -154,6 +159,15 @@ export class TasksMainImpl implements TasksMain, Disposable {
this.taskService.kill(id);
}

async $customExecutionComplete(id: string, result?: number): Promise<void> {
const tasks = await this.taskService.getRunningTasks();
const task = tasks.find(({ taskId }) => String(taskId) === id);
if (!task) {
throw new Error('Task to mark as complete not found');
}
await this.taskService.extensionCallbackTaskComplete(task, result);
}

protected createTaskProvider(handle: number): TaskProvider {
return {
provideTasks: () =>
Expand Down
2 changes: 2 additions & 0 deletions packages/plugin-ext/src/plugin/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ import {
ShellQuoting,
ShellExecution,
ProcessExecution,
CustomExecution,
TaskScope,
TaskPanelKind,
TaskRevealKind,
Expand Down Expand Up @@ -909,6 +910,7 @@ export function createAPIFactory(
ShellQuoting,
ShellExecution,
ProcessExecution,
CustomExecution,
TaskScope,
TaskRevealKind,
TaskPanelKind,
Expand Down
10 changes: 9 additions & 1 deletion packages/plugin-ext/src/plugin/type-converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ export function toWorkspaceFolder(folder: model.WorkspaceFolder): theia.Workspac
};
}

export function fromTask(task: theia.Task): TaskDto | undefined {
export function fromTask(task: theia.Task | undefined): TaskDto | undefined {
if (!task) {
return undefined;
}
Expand Down Expand Up @@ -753,6 +753,10 @@ export function fromTask(task: theia.Task): TaskDto | undefined {
return fromProcessExecution(<theia.ProcessExecution>execution, taskDto);
}

if (taskDefinition.type === 'customExecution' || execution instanceof theia.CustomExecution) {
return fromCustomExecution(<theia.CustomExecution>execution, taskDto);
}

return taskDto;
}

Expand Down Expand Up @@ -849,6 +853,10 @@ export function fromShellExecution(execution: theia.ShellExecution, taskDto: Tas
}
}

export function fromCustomExecution(execution: theia.CustomExecution, taskDto: TaskDto): TaskDto {
return taskDto;
}

export function getProcessExecution(taskDto: TaskDto): theia.ProcessExecution {
return new types.ProcessExecution(
taskDto.command,
Expand Down
23 changes: 21 additions & 2 deletions packages/plugin-ext/src/plugin/types-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,7 @@ export class ProcessExecution {
return computeTaskExecutionId(props);
}

public static is(value: theia.ShellExecution | theia.ProcessExecution): boolean {
public static is(value: theia.ShellExecution | theia.ProcessExecution | theia.CustomExecution): boolean {
const candidate = value as ProcessExecution;
return candidate && !!candidate.process;
}
Expand Down Expand Up @@ -1630,12 +1630,31 @@ export class ShellExecution {
return computeTaskExecutionId(props);
}

public static is(value: theia.ShellExecution | theia.ProcessExecution): boolean {
public static is(value: theia.ShellExecution | theia.ProcessExecution | theia.CustomExecution): boolean {
const candidate = value as ShellExecution;
return candidate && (!!candidate.commandLine || !!candidate.command);
}
}

export class CustomExecution implements theia.CustomExecution {

private _id?: string;
constructor(public callback: (resolvedDefinition: theia.TaskDefinition) => Thenable<theia.Pseudoterminal>) { }

computeId(): string {
if (!this._id) {
this._id = UUID.uuid4();
}
return `customExecution${this._id}`;
}

}
export namespace CustomExecution {
export function is(execution: theia.ShellExecution | theia.ProcessExecution | theia.CustomExecution): execution is theia.CustomExecution {
return execution instanceof theia.CustomExecution;
}
}

export class TaskGroup {
private groupId: string;

Expand Down
Loading

0 comments on commit e5939cd

Please sign in to comment.