mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
refactor: Store the CLI command directly in RustTargetDefinition
This commit is contained in:
parent
2e109c7da8
commit
4422a90b11
2 changed files with 18 additions and 14 deletions
|
@ -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),
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue