about summary refs log tree commit diff
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 7ecdeeeaf7f..766b0511269 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
         env: Object.assign({}, process.env as { [key: string]: string }, { "RUST_BACKTRACE": "short" }),
     };
 
-    const cargoTask = await tasks.buildCargoTask(definition, runnable.label, args, config.cargoRunner);
+    const target = vscode.workspace.workspaceFolders![0]; // safe, see main activate()
+    const cargoTask = await tasks.buildCargoTask(target, definition, runnable.label, args, config.cargoRunner, true);
     cargoTask.presentationOptions.clear = true;
 
     return cargoTask;
diff --git a/editors/code/src/tasks.ts b/editors/code/src/tasks.ts
index e2c43fdd418..20ddb3a5d97 100644
--- a/editors/code/src/tasks.ts
+++ b/editors/code/src/tasks.ts
@@ -24,43 +24,28 @@ class CargoTaskProvider implements vscode.TaskProvider {
         this.config = config;
     }
 
-    provideTasks(): vscode.Task[] {
+    async provideTasks(): Promise<vscode.Task[]> {
         // Detect Rust tasks. Currently we do not do any actual detection
         // of tasks (e.g. aliases in .cargo/config) and just return a fixed
         // set of tasks that always exist. These tasks cannot be removed in
         // tasks.json - only tweaked.
 
-        const cargoPath = toolchain.cargoPath();
-
-        return [
+        const defs = [
             { command: 'build', group: vscode.TaskGroup.Build },
             { command: 'check', group: vscode.TaskGroup.Build },
             { command: 'test', group: vscode.TaskGroup.Test },
             { command: 'clean', group: vscode.TaskGroup.Clean },
             { command: 'run', group: undefined },
-        ]
-            .map(({ command, group }) => {
-                const vscodeTask = new vscode.Task(
-                    // The contents of this object end up in the tasks.json entries.
-                    {
-                        type: TASK_TYPE,
-                        command,
-                    },
-                    // The scope of the task - workspace or specific folder (global
-                    // is not supported).
-                    this.target,
-                    // The task name, and task source. These are shown in the UI as
-                    // `${source}: ${name}`, e.g. `rust: cargo build`.
-                    `cargo ${command}`,
-                    'rust',
-                    // What to do when this command is executed.
-                    new vscode.ShellExecution(cargoPath, [command]),
-                    // Problem matchers.
-                    ['$rustc'],
-                );
-                vscodeTask.group = group;
-                return vscodeTask;
-            });
+        ];
+
+        const tasks: vscode.Task[] = [];
+        for (const def of defs) {
+            const vscodeTask = await buildCargoTask(this.target, { type: TASK_TYPE, command: def.command }, `cargo ${def.command}`, [def.command], this.config.cargoRunner);
+            vscodeTask.group = def.group;
+            tasks.push(vscodeTask);
+        }
+
+        return tasks;
     }
 
     async resolveTask(task: vscode.Task): Promise<vscode.Task | undefined> {
@@ -73,38 +58,56 @@ class CargoTaskProvider implements vscode.TaskProvider {
         if (definition.type === TASK_TYPE && definition.command) {
             const args = [definition.command].concat(definition.args ?? []);
 
-            return await buildCargoTask(definition, task.name, args, this.config.cargoRunner);
+            return await buildCargoTask(this.target, definition, task.name, args, this.config.cargoRunner);
         }
 
         return undefined;
     }
 }
 
-export async function buildCargoTask(definition: CargoTaskDefinition, name: string, args: string[], customRunner?: string): Promise<vscode.Task> {
+export async function buildCargoTask(
+    target: vscode.WorkspaceFolder,
+    definition: CargoTaskDefinition,
+    name: string,
+    args: string[],
+    customRunner?: string,
+    throwOnError: boolean = false
+): Promise<vscode.Task> {
+
+    let exec: vscode.ShellExecution | undefined = undefined;
+
     if (customRunner) {
-        const runnerCommand = `${customRunner}.createCargoTask`;
+        const runnerCommand = `${customRunner}.buildShellExecution`;
         try {
-            const runnerArgs = { name, args, cwd: definition.cwd, env: definition.env, source: TASK_SOURCE };
-            const task = await vscode.commands.executeCommand(runnerCommand, runnerArgs);
-
-            if (task instanceof vscode.Task) {
-                return task;
-            } else if (task) {
-                log.debug("Invalid cargo task", task);
-                throw `Invalid task!`;
+            const runnerArgs = { kind: TASK_TYPE, args, cwd: definition.cwd, env: definition.env };
+            const customExec = await vscode.commands.executeCommand(runnerCommand, runnerArgs);
+            if (customExec) {
+                if (customExec instanceof vscode.ShellExecution) {
+                    exec = customExec as vscode.ShellExecution;
+                } else {
+                    log.debug("Invalid cargo ShellExecution", customExec);
+                    throw "Invalid cargo ShellExecution.";
+                }
             }
             // fallback to default processing
 
         } catch (e) {
-            throw `Cargo runner '${customRunner}' failed! ${e}`;
+            if (throwOnError) throw `Cargo runner '${customRunner}' failed! ${e}`;
+            // fallback to default processing
         }
     }
 
+    if (!exec) {
+        exec = new vscode.ShellExecution(toolchain.cargoPath(), args, definition)
+    }
+
     return new vscode.Task(
         definition,
+        target,
         name,
         TASK_SOURCE,
-        new vscode.ShellExecution(toolchain.cargoPath(), args, definition),
+        exec,
+        ['$rustc']
     );
 }