aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src')
-rw-r--r--editors/code/src/run.ts3
-rw-r--r--editors/code/src/tasks.ts83
2 files changed, 45 insertions, 41 deletions
diff --git a/editors/code/src/run.ts b/editors/code/src/run.ts
index 7ecdeeeaf..766b05112 100644
--- a/editors/code/src/run.ts
+++ b/editors/code/src/run.ts
@@ -116,7 +116,8 @@ export async function createTask(runnable: ra.Runnable, config: Config): Promise
116 env: Object.assign({}, process.env as { [key: string]: string }, { "RUST_BACKTRACE": "short" }), 116 env: Object.assign({}, process.env as { [key: string]: string }, { "RUST_BACKTRACE": "short" }),
117 }; 117 };
118 118
119 const cargoTask = await tasks.buildCargoTask(definition, runnable.label, args, config.cargoRunner); 119 const target = vscode.workspace.workspaceFolders![0]; // safe, see main activate()
120 const cargoTask = await tasks.buildCargoTask(target, definition, runnable.label, args, config.cargoRunner, true);
120 cargoTask.presentationOptions.clear = true; 121 cargoTask.presentationOptions.clear = true;
121 122
122 return cargoTask; 123 return cargoTask;
diff --git a/editors/code/src/tasks.ts b/editors/code/src/tasks.ts
index e2c43fdd4..20ddb3a5d 100644
--- a/editors/code/src/tasks.ts
+++ b/editors/code/src/tasks.ts
@@ -24,43 +24,28 @@ class CargoTaskProvider implements vscode.TaskProvider {
24 this.config = config; 24 this.config = config;
25 } 25 }
26 26
27 provideTasks(): vscode.Task[] { 27 async provideTasks(): Promise<vscode.Task[]> {
28 // Detect Rust tasks. Currently we do not do any actual detection 28 // Detect Rust tasks. Currently we do not do any actual detection
29 // of tasks (e.g. aliases in .cargo/config) and just return a fixed 29 // of tasks (e.g. aliases in .cargo/config) and just return a fixed
30 // set of tasks that always exist. These tasks cannot be removed in 30 // set of tasks that always exist. These tasks cannot be removed in
31 // tasks.json - only tweaked. 31 // tasks.json - only tweaked.
32 32
33 const cargoPath = toolchain.cargoPath(); 33 const defs = [
34
35 return [
36 { command: 'build', group: vscode.TaskGroup.Build }, 34 { command: 'build', group: vscode.TaskGroup.Build },
37 { command: 'check', group: vscode.TaskGroup.Build }, 35 { command: 'check', group: vscode.TaskGroup.Build },
38 { command: 'test', group: vscode.TaskGroup.Test }, 36 { command: 'test', group: vscode.TaskGroup.Test },
39 { command: 'clean', group: vscode.TaskGroup.Clean }, 37 { command: 'clean', group: vscode.TaskGroup.Clean },
40 { command: 'run', group: undefined }, 38 { command: 'run', group: undefined },
41 ] 39 ];
42 .map(({ command, group }) => { 40
43 const vscodeTask = new vscode.Task( 41 const tasks: vscode.Task[] = [];
44 // The contents of this object end up in the tasks.json entries. 42 for (const def of defs) {
45 { 43 const vscodeTask = await buildCargoTask(this.target, { type: TASK_TYPE, command: def.command }, `cargo ${def.command}`, [def.command], this.config.cargoRunner);
46 type: TASK_TYPE, 44 vscodeTask.group = def.group;
47 command, 45 tasks.push(vscodeTask);
48 }, 46 }
49 // The scope of the task - workspace or specific folder (global 47
50 // is not supported). 48 return tasks;
51 this.target,
52 // The task name, and task source. These are shown in the UI as
53 // `${source}: ${name}`, e.g. `rust: cargo build`.
54 `cargo ${command}`,
55 'rust',
56 // What to do when this command is executed.
57 new vscode.ShellExecution(cargoPath, [command]),
58 // Problem matchers.
59 ['$rustc'],
60 );
61 vscodeTask.group = group;
62 return vscodeTask;
63 });
64 } 49 }
65 50
66 async resolveTask(task: vscode.Task): Promise<vscode.Task | undefined> { 51 async resolveTask(task: vscode.Task): Promise<vscode.Task | undefined> {
@@ -73,38 +58,56 @@ class CargoTaskProvider implements vscode.TaskProvider {
73 if (definition.type === TASK_TYPE && definition.command) { 58 if (definition.type === TASK_TYPE && definition.command) {
74 const args = [definition.command].concat(definition.args ?? []); 59 const args = [definition.command].concat(definition.args ?? []);
75 60
76 return await buildCargoTask(definition, task.name, args, this.config.cargoRunner); 61 return await buildCargoTask(this.target, definition, task.name, args, this.config.cargoRunner);
77 } 62 }
78 63
79 return undefined; 64 return undefined;
80 } 65 }
81} 66}
82 67
83export async function buildCargoTask(definition: CargoTaskDefinition, name: string, args: string[], customRunner?: string): Promise<vscode.Task> { 68export async function buildCargoTask(
69 target: vscode.WorkspaceFolder,
70 definition: CargoTaskDefinition,
71 name: string,
72 args: string[],
73 customRunner?: string,
74 throwOnError: boolean = false
75): Promise<vscode.Task> {
76
77 let exec: vscode.ShellExecution | undefined = undefined;
78
84 if (customRunner) { 79 if (customRunner) {
85 const runnerCommand = `${customRunner}.createCargoTask`; 80 const runnerCommand = `${customRunner}.buildShellExecution`;
86 try { 81 try {
87 const runnerArgs = { name, args, cwd: definition.cwd, env: definition.env, source: TASK_SOURCE }; 82 const runnerArgs = { kind: TASK_TYPE, args, cwd: definition.cwd, env: definition.env };
88 const task = await vscode.commands.executeCommand(runnerCommand, runnerArgs); 83 const customExec = await vscode.commands.executeCommand(runnerCommand, runnerArgs);
89 84 if (customExec) {
90 if (task instanceof vscode.Task) { 85 if (customExec instanceof vscode.ShellExecution) {
91 return task; 86 exec = customExec as vscode.ShellExecution;
92 } else if (task) { 87 } else {
93 log.debug("Invalid cargo task", task); 88 log.debug("Invalid cargo ShellExecution", customExec);
94 throw `Invalid task!`; 89 throw "Invalid cargo ShellExecution.";
90 }
95 } 91 }
96 // fallback to default processing 92 // fallback to default processing
97 93
98 } catch (e) { 94 } catch (e) {
99 throw `Cargo runner '${customRunner}' failed! ${e}`; 95 if (throwOnError) throw `Cargo runner '${customRunner}' failed! ${e}`;
96 // fallback to default processing
100 } 97 }
101 } 98 }
102 99
100 if (!exec) {
101 exec = new vscode.ShellExecution(toolchain.cargoPath(), args, definition)
102 }
103
103 return new vscode.Task( 104 return new vscode.Task(
104 definition, 105 definition,
106 target,
105 name, 107 name,
106 TASK_SOURCE, 108 TASK_SOURCE,
107 new vscode.ShellExecution(toolchain.cargoPath(), args, definition), 109 exec,
110 ['$rustc']
108 ); 111 );
109} 112}
110 113