Unnamed repository; edit this file 'description' to name the repository.
refactor: Store the CLI command directly in RustTargetDefinition
Wilfred Hughes 2024-03-15
parent 2e109c7 · commit 4422a90
-rw-r--r--editors/code/src/run.ts14
-rw-r--r--editors/code/src/tasks.ts18
2 files changed, 18 insertions, 14 deletions
diff --git a/editors/code/src/run.ts b/editors/code/src/run.ts
index b6c730a4cd..02ccbb6956 100644
--- a/editors/code/src/run.ts
+++ b/editors/code/src/run.ts
@@ -2,6 +2,7 @@ import * as vscode from "vscode";
import type * as lc from "vscode-languageclient";
import * as ra from "./lsp_ext";
import * as tasks from "./tasks";
+import * as toolchain from "./toolchain";
import type { CtxInit } from "./ctx";
import { makeDebugConfig } from "./debug";
@@ -111,10 +112,21 @@ export async function createTask(runnable: ra.Runnable, config: Config): Promise
throw `Unexpected runnable kind: ${runnable.kind}`;
}
- const args = createArgs(runnable);
+ let program: string;
+ let args = createArgs(runnable);
+ if (runnable.args.overrideCargo) {
+ // Split on spaces to allow overrides like "wrapper cargo".
+ const cargoParts = runnable.args.overrideCargo.split(" ");
+
+ program = unwrapUndefinable(cargoParts[0]);
+ args = [...cargoParts.slice(1), ...args];
+ } else {
+ program = await toolchain.cargoPath();
+ }
const definition: tasks.RustTargetDefinition = {
type: tasks.TASK_TYPE,
+ program,
args,
cwd: runnable.args.workspaceRoot || ".",
env: prepareEnv(runnable, config.runnablesExtraEnv),
diff --git a/editors/code/src/tasks.ts b/editors/code/src/tasks.ts
index 39684b4165..89abb37b0e 100644
--- a/editors/code/src/tasks.ts
+++ b/editors/code/src/tasks.ts
@@ -2,7 +2,6 @@ import * as vscode from "vscode";
import * as toolchain from "./toolchain";
import type { Config } from "./config";
import { log } from "./util";
-import { unwrapUndefinable } from "./undefinable";
// This ends up as the `type` key in tasks.json. RLS also uses `cargo` and
// our configuration should be compatible with it so use the same key.
@@ -10,10 +9,10 @@ export const TASK_TYPE = "cargo";
export const TASK_SOURCE = "rust";
export interface RustTargetDefinition extends vscode.TaskDefinition {
+ program: string;
args: string[];
cwd?: string;
env?: { [key: string]: string };
- overrideCargo?: string;
}
class RustTaskProvider implements vscode.TaskProvider {
@@ -38,12 +37,14 @@ class RustTaskProvider implements vscode.TaskProvider {
{ command: "run", group: undefined },
];
+ const cargoPath = await toolchain.cargoPath();
+
const tasks: vscode.Task[] = [];
for (const workspaceTarget of vscode.workspace.workspaceFolders || []) {
for (const def of defs) {
const vscodeTask = await buildRustTask(
workspaceTarget,
- { type: TASK_TYPE, args: [def.command] },
+ { type: TASK_TYPE, program: cargoPath, args: [def.command] },
`cargo ${def.command}`,
this.config.problemMatcher,
this.config.cargoRunner,
@@ -113,16 +114,7 @@ export async function buildRustTask(
}
if (!exec) {
- // Check whether we must use a user-defined substitute for cargo.
- // Split on spaces to allow overrides like "wrapper cargo".
- const overrideCargo = definition.overrideCargo ?? definition.overrideCargo;
- const cargoPath = await toolchain.cargoPath();
- const cargoCommand = overrideCargo?.split(" ") ?? [cargoPath];
-
- const fullCommand = [...cargoCommand, ...definition.args];
-
- const processName = unwrapUndefinable(fullCommand[0]);
- exec = new vscode.ProcessExecution(processName, fullCommand.slice(1), definition);
+ exec = new vscode.ProcessExecution(definition.program, definition.args, definition);
}
return new vscode.Task(