-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
task-protocol.ts
105 lines (92 loc) · 4.01 KB
/
task-protocol.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/********************************************************************************
* Copyright (C) 2017 Ericsson and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { JsonRpcServer } from '@theia/core/lib/common/messaging/proxy-factory';
export const taskPath = '/services/task';
export const TaskServer = Symbol('TaskServer');
export const TaskClient = Symbol('TaskClient');
export interface TaskConfiguration {
/** A label that uniquely identifies a task configuration per source */
readonly label: string;
readonly type: string;
/** Additional task type specific properties. */
// tslint:disable-next-line:no-any
readonly [key: string]: any;
}
export namespace TaskConfiguration {
export function equals(one: TaskConfiguration, other: TaskConfiguration): boolean {
return one.label === other.label && one._source === other._source;
}
}
export interface ContributedTaskConfiguration extends TaskConfiguration {
/**
* Source of the task configuration.
* For a configured task, it is the name of the root folder, while for a provided task, it is the name of the provider.
* This field is not supposed to be used in `tasks.json`
*/
readonly _source: string;
/**
* For a provided task, it is the string representation of the URI where the task is supposed to run from. It is `undefined` for global tasks.
* This field is not supposed to be used in `tasks.json`
*/
readonly _scope: string | undefined;
}
export namespace ContributedTaskConfiguration {
export function is(config: TaskConfiguration | undefined): config is ContributedTaskConfiguration {
return !!config && '_source' in config && '_scope' in config;
}
}
/** Runtime information about Task. */
export interface TaskInfo {
/** internal unique task id */
readonly taskId: number,
/** terminal id. Defined if task is run as a terminal process */
readonly terminalId?: number,
/** context that was passed as part of task creation, if any */
readonly ctx?: string,
/** task config used for launching a task */
readonly config: TaskConfiguration,
/** Additional properties specific for a particular Task Runner. */
// tslint:disable-next-line:no-any
readonly [key: string]: any;
}
export interface TaskServer extends JsonRpcServer<TaskClient> {
/** Run a task. Optionally pass a context. */
run(task: TaskConfiguration, ctx?: string): Promise<TaskInfo>;
/** Kill a task, by id. */
kill(taskId: number): Promise<void>;
/**
* Returns a list of currently running tasks. If a context is provided,
* only the tasks started in that context will be provided. Using an
* undefined context matches all tasks, no matter the creation context.
*/
getTasks(ctx?: string): Promise<TaskInfo[]>
/** removes the client that has disconnected */
disconnectClient(client: TaskClient): void;
/** Returns the list of default and registered task runners */
getRegisteredTaskTypes(): Promise<string[]>
}
/** Event sent when a task has concluded its execution */
export interface TaskExitedEvent {
readonly taskId: number;
readonly ctx?: string;
// Exactly one of code and signal will be set.
readonly code?: number;
readonly signal?: string;
}
export interface TaskClient {
onTaskExit(event: TaskExitedEvent): void;
onTaskCreated(event: TaskInfo): void;
}