aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/tasks.ts
diff options
context:
space:
mode:
authorTim <[email protected]>2020-03-30 18:12:22 +0100
committerTim Hutt <[email protected]>2020-03-30 21:23:21 +0100
commit768aa4259fce15f313042892739ed4d8b7e518b4 (patch)
treef50618675b04ea7d29490fc942fb6cde6b3c161a /editors/code/src/tasks.ts
parent671926ac93f0ff921758a919eaf87c056979189f (diff)
Add basic task support
This adds basic support for running `cargo build`, `cargo run`, etc.
Diffstat (limited to 'editors/code/src/tasks.ts')
-rw-r--r--editors/code/src/tasks.ts60
1 files changed, 60 insertions, 0 deletions
diff --git a/editors/code/src/tasks.ts b/editors/code/src/tasks.ts
new file mode 100644
index 000000000..be036b872
--- /dev/null
+++ b/editors/code/src/tasks.ts
@@ -0,0 +1,60 @@
1import {
2 Disposable,
3 ShellExecution,
4 Task,
5 TaskGroup,
6 TaskProvider,
7 tasks,
8 WorkspaceFolder,
9} from 'vscode';
10
11// This ends up as the `type` key in tasks.json. RLS also uses `cargo` and
12// our configuration should be compatible with it so use the same key.
13const TASK_TYPE = 'cargo';
14
15export function activateTaskProvider(target: WorkspaceFolder): Disposable {
16 const provider: TaskProvider = {
17 // Detect Rust tasks. Currently we do not do any actual detection
18 // of tasks (e.g. aliases in .cargo/config) and just return a fixed
19 // set of tasks that always exist. These tasks cannot be removed in
20 // tasks.json - only tweaked.
21 provideTasks: () => getStandardCargoTasks(target),
22
23 // We don't need to implement this.
24 resolveTask: () => undefined,
25 };
26
27 return tasks.registerTaskProvider(TASK_TYPE, provider);
28}
29
30function getStandardCargoTasks(target: WorkspaceFolder): Task[] {
31 return [
32 { command: 'build', group: TaskGroup.Build },
33 { command: 'check', group: TaskGroup.Build },
34 { command: 'test', group: TaskGroup.Test },
35 { command: 'clean', group: TaskGroup.Clean },
36 { command: 'run', group: undefined },
37 ]
38 .map(({ command, group }) => {
39 const vscodeTask = new Task(
40 // The contents of this object end up in the tasks.json entries.
41 {
42 type: TASK_TYPE,
43 command,
44 },
45 // The scope of the task - workspace or specific folder (global
46 // is not supported).
47 target,
48 // The task name, and task source. These are shown in the UI as
49 // `${source}: ${name}`, e.g. `rust: cargo build`.
50 `cargo ${command}`,
51 'rust',
52 // What to do when this command is executed.
53 new ShellExecution('cargo', [command]),
54 // Problem matchers.
55 ['$rustc'],
56 );
57 vscodeTask.group = group;
58 return vscodeTask;
59 });
60}