Skip to content

Commit 5b26629

Browse files
committed
Support 'runnables' options in the vs code extension
1 parent 4a1b4b2 commit 5b26629

File tree

5 files changed

+31
-2
lines changed

5 files changed

+31
-2
lines changed

editors/code/package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,22 @@
651651
],
652652
"default": "full",
653653
"description": "The strategy to use when inserting new imports or merging imports."
654+
},
655+
"rust-analyzer.runnables.overrideCargo": {
656+
"type": [
657+
"null",
658+
"string"
659+
],
660+
"default": null,
661+
"description": "Command to be executed instead of 'cargo' for runnables."
662+
},
663+
"rust-analyzer.runnables.cargoExtraArgs": {
664+
"type": "array",
665+
"items": {
666+
"type": "string"
667+
},
668+
"default": [],
669+
"description": "Additional arguments to be passed to cargo for runnables such as tests or binaries.\nFor example, it may be '--release'"
654670
}
655671
}
656672
},

editors/code/src/lsp_ext.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ export interface Runnable {
6969
args: {
7070
workspaceRoot?: string;
7171
cargoArgs: string[];
72+
cargoExtraArgs: string[];
7273
executableArgs: string[];
7374
expectTest?: boolean;
75+
overrideCargo?: string;
7476
};
7577
}
7678
export const runnables = new lc.RequestType<RunnablesParams, Runnable[], void>("experimental/runnables");

editors/code/src/run.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ export async function createTask(runnable: ra.Runnable, config: Config): Promise
129129
}
130130

131131
const args = [...runnable.args.cargoArgs]; // should be a copy!
132+
args.push(...runnable.args.cargoExtraArgs); // Append user-specified cargo options.
132133
if (runnable.args.executableArgs.length > 0) {
133134
args.push('--', ...runnable.args.executableArgs);
134135
}
@@ -139,6 +140,7 @@ export async function createTask(runnable: ra.Runnable, config: Config): Promise
139140
args: args.slice(1),
140141
cwd: runnable.args.workspaceRoot || ".",
141142
env: prepareEnv(runnable, config.runnableEnv),
143+
overrideCargo: runnable.args.overrideCargo,
142144
};
143145

144146
const target = vscode.workspace.workspaceFolders![0]; // safe, see main activate()

editors/code/src/tasks.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface CargoTaskDefinition extends vscode.TaskDefinition {
1313
args?: string[];
1414
cwd?: string;
1515
env?: { [key: string]: string };
16+
overrideCargo?: string;
1617
}
1718

1819
class CargoTaskProvider implements vscode.TaskProvider {
@@ -98,7 +99,14 @@ export async function buildCargoTask(
9899
}
99100

100101
if (!exec) {
101-
exec = new vscode.ShellExecution(toolchain.cargoPath(), args, definition);
102+
// Check whether we must use a user-defined substitute for cargo.
103+
const cargoCommand = definition.overrideCargo ? definition.overrideCargo : toolchain.cargoPath();
104+
105+
// Prepare the whole command as one line. It is required if user has provided override command which contains spaces,
106+
// for example "wrapper cargo". Without manual preparation the overridden command will be quoted and fail to execute.
107+
const fullCommand = [cargoCommand, ...args].join(" ");
108+
109+
exec = new vscode.ShellExecution(fullCommand, definition);
102110
}
103111

104112
return new vscode.Task(

editors/code/tests/unit/runnable_env.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ function makeRunnable(label: string): ra.Runnable {
99
kind: "cargo",
1010
args: {
1111
cargoArgs: [],
12-
executableArgs: []
12+
executableArgs: [],
13+
cargoExtraArgs: []
1314
}
1415
};
1516
}

0 commit comments

Comments
 (0)