Skip to content

Commit b41a134

Browse files
Merge pull request #21978 from shorwood/feat/granular-override-placeholders
feat: enhance runnable command placeholders
2 parents 4fac9df + 4be95c4 commit b41a134

4 files changed

Lines changed: 74 additions & 24 deletions

File tree

crates/rust-analyzer/src/config.rs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -960,18 +960,30 @@ config_data! {
960960
/// Override the command used for bench runnables.
961961
/// The first element of the array should be the program to execute (for example, `cargo`).
962962
///
963-
/// Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${executable_args}` to dynamically
964-
/// replace the package name, target option (such as `--bin` or `--example`), the target name and
965-
/// the arguments passed to test binary args (includes `rust-analyzer.runnables.extraTestBinaryArgs`).
963+
/// Use the placeholders:
964+
/// - `${package}`: package name.
965+
/// - `${target_arg}`: target option such as `--bin`, `--test`, `--lib`, etc.
966+
/// - `${target}`: target name (empty for `--lib`).
967+
/// - `${test_name}`: the test path filter, e.g. `module::bench_func`.
968+
/// - `${exact}`: `--exact` for single benchmarks, empty for modules.
969+
/// - `${include_ignored}`: always empty for benchmarks.
970+
/// - `${executable_args}`: all of the above binary args bundled together
971+
/// (includes `rust-analyzer.runnables.extraTestBinaryArgs`).
966972
runnables_bench_overrideCommand: Option<Vec<String>> = None,
967973
/// Command to be executed instead of 'cargo' for runnables.
968974
runnables_command: Option<String> = None,
969-
/// Override the command used for bench runnables.
975+
/// Override the command used for doc-test runnables.
970976
/// The first element of the array should be the program to execute (for example, `cargo`).
971977
///
972-
/// Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${executable_args}` to dynamically
973-
/// replace the package name, target option (such as `--bin` or `--example`), the target name and
974-
/// the arguments passed to test binary args (includes `rust-analyzer.runnables.extraTestBinaryArgs`).
978+
/// Use the placeholders:
979+
/// - `${package}`: package name.
980+
/// - `${target_arg}`: target option such as `--bin`, `--test`, `--lib`, etc.
981+
/// - `${target}`: target name (empty for `--lib`).
982+
/// - `${test_name}`: the test path filter, e.g. `module::func`.
983+
/// - `${exact}`: always empty for doc-tests.
984+
/// - `${include_ignored}`: always empty for doc-tests.
985+
/// - `${executable_args}`: all of the above binary args bundled together
986+
/// (includes `rust-analyzer.runnables.extraTestBinaryArgs`).
975987
runnables_doctest_overrideCommand: Option<Vec<String>> = None,
976988
/// Additional arguments to be passed to cargo for runnables such as
977989
/// tests or binaries. For example, it may be `--release`.
@@ -989,9 +1001,15 @@ config_data! {
9891001
/// Override the command used for test runnables.
9901002
/// The first element of the array should be the program to execute (for example, `cargo`).
9911003
///
992-
/// Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${executable_args}` to dynamically
993-
/// replace the package name, target option (such as `--bin` or `--example`), the target name and
994-
/// the arguments passed to test binary args (includes `rust-analyzer.runnables.extraTestBinaryArgs`).
1004+
/// Available placeholders:
1005+
/// - `${package}`: package name.
1006+
/// - `${target_arg}`: target option such as `--bin`, `--test`, `--lib`, etc.
1007+
/// - `${target}`: target name (empty for `--lib`).
1008+
/// - `${test_name}`: the test path filter, e.g. `module::test_func`.
1009+
/// - `${exact}`: `--exact` for single tests, empty for modules.
1010+
/// - `${include_ignored}`: `--include-ignored` for single tests, empty otherwise.
1011+
/// - `${executable_args}`: all of the above binary args bundled together
1012+
/// (includes `rust-analyzer.runnables.extraTestBinaryArgs`).
9951013
runnables_test_overrideCommand: Option<Vec<String>> = None,
9961014

9971015
/// Path to the Cargo.toml of the rust compiler workspace, for usage in rustc_private

crates/rust-analyzer/src/target_spec.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,18 @@ impl CargoTargetSpec {
230230
};
231231
let test_name = test_name.unwrap_or_default();
232232

233+
let exact = match kind {
234+
RunnableKind::Test { test_id } | RunnableKind::Bench { test_id } => match test_id {
235+
TestId::Path(_) => "--exact",
236+
TestId::Name(_) => "",
237+
},
238+
_ => "",
239+
};
240+
let include_ignored = match kind {
241+
RunnableKind::Test { .. } => "--include-ignored",
242+
_ => "",
243+
};
244+
233245
let target_arg = |kind| match kind {
234246
TargetKind::Bin => "--bin",
235247
TargetKind::Test => "--test",
@@ -249,7 +261,9 @@ impl CargoTargetSpec {
249261
.replace("${package}", &spec.package)
250262
.replace("${target_arg}", target_arg(spec.target_kind))
251263
.replace("${target}", target(spec.target_kind, &spec.target))
252-
.replace("${test_name}", &test_name),
264+
.replace("${test_name}", &test_name)
265+
.replace("${exact}", exact)
266+
.replace("${include_ignored}", include_ignored),
253267
_ => arg,
254268
};
255269

docs/book/src/configuration_generated.md

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,9 +1404,15 @@ Default: `null`
14041404
Override the command used for bench runnables.
14051405
The first element of the array should be the program to execute (for example, `cargo`).
14061406

1407-
Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${executable_args}` to dynamically
1408-
replace the package name, target option (such as `--bin` or `--example`), the target name and
1409-
the arguments passed to test binary args (includes `rust-analyzer.runnables.extraTestBinaryArgs`).
1407+
Use the placeholders:
1408+
- `${package}`: package name.
1409+
- `${target_arg}`: target option such as `--bin`, `--test`, `--lib`, etc.
1410+
- `${target}`: target name (empty for `--lib`).
1411+
- `${test_name}`: the test path filter, e.g. `module::bench_func`.
1412+
- `${exact}`: `--exact` for single benchmarks, empty for modules.
1413+
- `${include_ignored}`: always empty for benchmarks.
1414+
- `${executable_args}`: all of the above binary args bundled together
1415+
(includes `rust-analyzer.runnables.extraTestBinaryArgs`).
14101416

14111417

14121418
## rust-analyzer.runnables.command {#runnables.command}
@@ -1420,12 +1426,18 @@ Command to be executed instead of 'cargo' for runnables.
14201426

14211427
Default: `null`
14221428

1423-
Override the command used for bench runnables.
1429+
Override the command used for doc-test runnables.
14241430
The first element of the array should be the program to execute (for example, `cargo`).
14251431

1426-
Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${executable_args}` to dynamically
1427-
replace the package name, target option (such as `--bin` or `--example`), the target name and
1428-
the arguments passed to test binary args (includes `rust-analyzer.runnables.extraTestBinaryArgs`).
1432+
Use the placeholders:
1433+
- `${package}`: package name.
1434+
- `${target_arg}`: target option such as `--bin`, `--test`, `--lib`, etc.
1435+
- `${target}`: target name (empty for `--lib`).
1436+
- `${test_name}`: the test path filter, e.g. `module::func`.
1437+
- `${exact}`: always empty for doc-tests.
1438+
- `${include_ignored}`: always empty for doc-tests.
1439+
- `${executable_args}`: all of the above binary args bundled together
1440+
(includes `rust-analyzer.runnables.extraTestBinaryArgs`).
14291441

14301442

14311443
## rust-analyzer.runnables.extraArgs {#runnables.extraArgs}
@@ -1468,9 +1480,15 @@ Default: `null`
14681480
Override the command used for test runnables.
14691481
The first element of the array should be the program to execute (for example, `cargo`).
14701482

1471-
Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${executable_args}` to dynamically
1472-
replace the package name, target option (such as `--bin` or `--example`), the target name and
1473-
the arguments passed to test binary args (includes `rust-analyzer.runnables.extraTestBinaryArgs`).
1483+
Available placeholders:
1484+
- `${package}`: package name.
1485+
- `${target_arg}`: target option such as `--bin`, `--test`, `--lib`, etc.
1486+
- `${target}`: target name (empty for `--lib`).
1487+
- `${test_name}`: the test path filter, e.g. `module::test_func`.
1488+
- `${exact}`: `--exact` for single tests, empty for modules.
1489+
- `${include_ignored}`: `--include-ignored` for single tests, empty otherwise.
1490+
- `${executable_args}`: all of the above binary args bundled together
1491+
(includes `rust-analyzer.runnables.extraTestBinaryArgs`).
14741492

14751493

14761494
## rust-analyzer.rustc.source {#rustc.source}

editors/code/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2909,7 +2909,7 @@
29092909
"title": "Runnables",
29102910
"properties": {
29112911
"rust-analyzer.runnables.bench.overrideCommand": {
2912-
"markdownDescription": "Override the command used for bench runnables.\nThe first element of the array should be the program to execute (for example, `cargo`).\n\nUse the placeholders `${package}`, `${target_arg}`, `${target}`, `${executable_args}` to dynamically\nreplace the package name, target option (such as `--bin` or `--example`), the target name and\nthe arguments passed to test binary args (includes `rust-analyzer.runnables.extraTestBinaryArgs`).",
2912+
"markdownDescription": "Override the command used for bench runnables.\nThe first element of the array should be the program to execute (for example, `cargo`).\n\nUse the placeholders:\n- `${package}`: package name.\n- `${target_arg}`: target option such as `--bin`, `--test`, `--lib`, etc.\n- `${target}`: target name (empty for `--lib`).\n- `${test_name}`: the test path filter, e.g. `module::bench_func`.\n- `${exact}`: `--exact` for single benchmarks, empty for modules.\n- `${include_ignored}`: always empty for benchmarks.\n- `${executable_args}`: all of the above binary args bundled together\n (includes `rust-analyzer.runnables.extraTestBinaryArgs`).",
29132913
"default": null,
29142914
"type": [
29152915
"null",
@@ -2938,7 +2938,7 @@
29382938
"title": "Runnables",
29392939
"properties": {
29402940
"rust-analyzer.runnables.doctest.overrideCommand": {
2941-
"markdownDescription": "Override the command used for bench runnables.\nThe first element of the array should be the program to execute (for example, `cargo`).\n\nUse the placeholders `${package}`, `${target_arg}`, `${target}`, `${executable_args}` to dynamically\nreplace the package name, target option (such as `--bin` or `--example`), the target name and\nthe arguments passed to test binary args (includes `rust-analyzer.runnables.extraTestBinaryArgs`).",
2941+
"markdownDescription": "Override the command used for doc-test runnables.\nThe first element of the array should be the program to execute (for example, `cargo`).\n\nUse the placeholders:\n- `${package}`: package name.\n- `${target_arg}`: target option such as `--bin`, `--test`, `--lib`, etc.\n- `${target}`: target name (empty for `--lib`).\n- `${test_name}`: the test path filter, e.g. `module::func`.\n- `${exact}`: always empty for doc-tests.\n- `${include_ignored}`: always empty for doc-tests.\n- `${executable_args}`: all of the above binary args bundled together\n (includes `rust-analyzer.runnables.extraTestBinaryArgs`).",
29422942
"default": null,
29432943
"type": [
29442944
"null",
@@ -2992,7 +2992,7 @@
29922992
"title": "Runnables",
29932993
"properties": {
29942994
"rust-analyzer.runnables.test.overrideCommand": {
2995-
"markdownDescription": "Override the command used for test runnables.\nThe first element of the array should be the program to execute (for example, `cargo`).\n\nUse the placeholders `${package}`, `${target_arg}`, `${target}`, `${executable_args}` to dynamically\nreplace the package name, target option (such as `--bin` or `--example`), the target name and\nthe arguments passed to test binary args (includes `rust-analyzer.runnables.extraTestBinaryArgs`).",
2995+
"markdownDescription": "Override the command used for test runnables.\nThe first element of the array should be the program to execute (for example, `cargo`).\n\nAvailable placeholders:\n- `${package}`: package name.\n- `${target_arg}`: target option such as `--bin`, `--test`, `--lib`, etc.\n- `${target}`: target name (empty for `--lib`).\n- `${test_name}`: the test path filter, e.g. `module::test_func`.\n- `${exact}`: `--exact` for single tests, empty for modules.\n- `${include_ignored}`: `--include-ignored` for single tests, empty otherwise.\n- `${executable_args}`: all of the above binary args bundled together\n (includes `rust-analyzer.runnables.extraTestBinaryArgs`).",
29962996
"default": null,
29972997
"type": [
29982998
"null",

0 commit comments

Comments
 (0)