refactor: Use a single CLI args array rather than a separate subcommand field

This commit is contained in:
Wilfred Hughes 2024-03-13 16:46:57 -07:00
parent d472fd932b
commit 2e109c7da8
2 changed files with 11 additions and 13 deletions

View file

@ -115,8 +115,7 @@ export async function createTask(runnable: ra.Runnable, config: Config): Promise
const definition: tasks.RustTargetDefinition = {
type: tasks.TASK_TYPE,
command: args[0], // run, test, etc...
args: args.slice(1),
args,
cwd: runnable.args.workspaceRoot || ".",
env: prepareEnv(runnable, config.runnablesExtraEnv),
overrideCargo: runnable.args.overrideCargo,
@ -128,7 +127,6 @@ export async function createTask(runnable: ra.Runnable, config: Config): Promise
target,
definition,
runnable.label,
args,
config.problemMatcher,
config.cargoRunner,
true,

View file

@ -10,8 +10,7 @@ export const TASK_TYPE = "cargo";
export const TASK_SOURCE = "rust";
export interface RustTargetDefinition extends vscode.TaskDefinition {
command?: string;
args?: string[];
args: string[];
cwd?: string;
env?: { [key: string]: string };
overrideCargo?: string;
@ -44,9 +43,8 @@ class RustTaskProvider implements vscode.TaskProvider {
for (const def of defs) {
const vscodeTask = await buildRustTask(
workspaceTarget,
{ type: TASK_TYPE, command: def.command },
{ type: TASK_TYPE, args: [def.command] },
`cargo ${def.command}`,
[def.command],
this.config.problemMatcher,
this.config.cargoRunner,
);
@ -65,13 +63,11 @@ class RustTaskProvider implements vscode.TaskProvider {
const definition = task.definition as RustTargetDefinition;
if (definition.type === TASK_TYPE && definition.command) {
const args = [definition.command].concat(definition.args ?? []);
if (definition.type === TASK_TYPE) {
return await buildRustTask(
task.scope,
definition,
task.name,
args,
this.config.problemMatcher,
this.config.cargoRunner,
);
@ -85,7 +81,6 @@ export async function buildRustTask(
scope: vscode.WorkspaceFolder | vscode.TaskScope | undefined,
definition: RustTargetDefinition,
name: string,
args: string[],
problemMatcher: string[],
customRunner?: string,
throwOnError: boolean = false,
@ -95,7 +90,12 @@ export async function buildRustTask(
if (customRunner) {
const runnerCommand = `${customRunner}.buildShellExecution`;
try {
const runnerArgs = { kind: TASK_TYPE, args, cwd: definition.cwd, env: definition.env };
const runnerArgs = {
kind: TASK_TYPE,
args: definition.args,
cwd: definition.cwd,
env: definition.env,
};
const customExec = await vscode.commands.executeCommand(runnerCommand, runnerArgs);
if (customExec) {
if (customExec instanceof vscode.ShellExecution) {
@ -119,7 +119,7 @@ export async function buildRustTask(
const cargoPath = await toolchain.cargoPath();
const cargoCommand = overrideCargo?.split(" ") ?? [cargoPath];
const fullCommand = [...cargoCommand, ...args];
const fullCommand = [...cargoCommand, ...definition.args];
const processName = unwrapUndefinable(fullCommand[0]);
exec = new vscode.ProcessExecution(processName, fullCommand.slice(1), definition);