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

View file

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