Skip to content

Commit 52af033

Browse files
committed
chore: add test_name placeholder in config
1 parent 159e7f4 commit 52af033

5 files changed

Lines changed: 41 additions & 27 deletions

File tree

crates/rust-analyzer/src/config.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -909,16 +909,18 @@ config_data! {
909909
/// Override the command used for bench runnables.
910910
/// The first element of the array should be the program to execute (for example, `cargo`).
911911
///
912-
/// Use the placeholders `${package}`, `${target_arg}`, `${target}` to dynamically replace the package name,
913-
/// target option (such as `--bin` or `--example`), and the target name.
912+
/// Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${test_name}` to dynamically
913+
/// replace the package name, target option (such as `--bin` or `--example`), the target name and
914+
/// the test name (name of test function or test mod path).
914915
runnables_bench_overrideCommand: Option<Vec<String>> = None,
915916
/// Command to be executed instead of 'cargo' for runnables.
916917
runnables_command: Option<String> = None,
917918
/// Override the command used for bench runnables.
918919
/// The first element of the array should be the program to execute (for example, `cargo`).
919920
///
920-
/// Use the placeholders `${package}`, `${target_arg}`, `${target}` to dynamically replace the package name,
921-
/// target option (such as `--bin` or `--example`), and the target name.
921+
/// Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${test_name}` to dynamically
922+
/// replace the package name, target option (such as `--bin` or `--example`), the target name and
923+
/// the test name (name of test function or test mod path).
922924
runnables_doctest_overrideCommand: Option<Vec<String>> = None,
923925
/// Additional arguments to be passed to cargo for runnables such as
924926
/// tests or binaries. For example, it may be `--release`.
@@ -936,8 +938,9 @@ config_data! {
936938
/// Override the command used for test runnables.
937939
/// The first element of the array should be the program to execute (for example, `cargo`).
938940
///
939-
/// Use the placeholders `${package}`, `${target_arg}`, `${target}` to dynamically replace the package name,
940-
/// target option (such as `--bin` or `--example`), and the target name.
941+
/// Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${test_name}` to dynamically
942+
/// replace the package name, target option (such as `--bin` or `--example`), the target name and
943+
/// the test name (name of test function or test mod path).
941944
runnables_test_overrideCommand: Option<Vec<String>> = None,
942945

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

crates/rust-analyzer/src/lsp/to_proto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,7 @@ pub(crate) fn runnable(
15951595
environment,
15961596
cwd: cwd.into(),
15971597
program: program.to_string(),
1598-
args: args.iter().cloned().chain(executable_args).collect(),
1598+
args: args.to_vec(),
15991599
}),
16001600
}),
16011601
_ => None,

crates/rust-analyzer/src/target_spec.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -214,19 +214,25 @@ impl CargoTargetSpec {
214214
kind: &RunnableKind,
215215
) -> Option<Vec<String>> {
216216
let config = snap.config.runnables(None);
217-
let args = match kind {
218-
RunnableKind::Test { .. } | RunnableKind::TestMod { .. } => {
219-
config.test_override_command
217+
let (args, test_name) = match kind {
218+
RunnableKind::Test { test_id, .. } => {
219+
(config.test_override_command, Some(test_id.to_string()))
220+
}
221+
RunnableKind::TestMod { path } => (config.test_override_command, Some(path.clone())),
222+
RunnableKind::Bench { test_id } => {
223+
(config.bench_override_command, Some(test_id.to_string()))
224+
}
225+
RunnableKind::DocTest { test_id } => {
226+
(config.doc_test_override_command, Some(test_id.to_string()))
220227
}
221-
RunnableKind::Bench { .. } => config.bench_override_command,
222-
RunnableKind::DocTest { .. } => config.doc_test_override_command,
223228
RunnableKind::Bin => match spec {
224229
Some(CargoTargetSpec { target_kind: TargetKind::Test, .. }) => {
225-
config.test_override_command
230+
(config.test_override_command, None)
226231
}
227-
_ => None,
232+
_ => (None, None),
228233
},
229234
};
235+
let test_name = test_name.unwrap_or_default();
230236

231237
let target_arg = |kind| match kind {
232238
TargetKind::Bin => "--bin",
@@ -237,10 +243,12 @@ impl CargoTargetSpec {
237243
TargetKind::BuildScript | TargetKind::Other => "",
238244
};
239245

240-
let replace_placeholders = |arg| match &spec {
241-
Some(spec) if arg == "${package}" => spec.package.clone(),
242-
Some(spec) if arg == "${target_arg}" => target_arg(spec.target_kind).to_owned(),
243-
Some(spec) if arg == "${target}" => spec.target.clone(),
246+
let replace_placeholders = |arg: String| match &spec {
247+
Some(spec) => arg
248+
.replace("${package}", &spec.package)
249+
.replace("${target_arg}", target_arg(spec.target_kind))
250+
.replace("${target}", &spec.target)
251+
.replace("${test_name}", &test_name),
244252
_ => arg,
245253
};
246254

docs/book/src/configuration_generated.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,8 +1362,9 @@ Default: `null`
13621362
Override the command used for bench runnables.
13631363
The first element of the array should be the program to execute (for example, `cargo`).
13641364

1365-
Use the placeholders `${package}`, `${target_arg}`, `${target}` to dynamically replace the package name,
1366-
target option (such as `--bin` or `--example`), and the target name.
1365+
Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${test_name}` to dynamically
1366+
replace the package name, target option (such as `--bin` or `--example`), the target name and
1367+
the test name (name of test function or test mod path).
13671368

13681369

13691370
## rust-analyzer.runnables.command {#runnables.command}
@@ -1380,8 +1381,9 @@ Default: `null`
13801381
Override the command used for bench runnables.
13811382
The first element of the array should be the program to execute (for example, `cargo`).
13821383

1383-
Use the placeholders `${package}`, `${target_arg}`, `${target}` to dynamically replace the package name,
1384-
target option (such as `--bin` or `--example`), and the target name.
1384+
Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${test_name}` to dynamically
1385+
replace the package name, target option (such as `--bin` or `--example`), the target name and
1386+
the test name (name of test function or test mod path).
13851387

13861388

13871389
## rust-analyzer.runnables.extraArgs {#runnables.extraArgs}
@@ -1424,8 +1426,9 @@ Default: `null`
14241426
Override the command used for test runnables.
14251427
The first element of the array should be the program to execute (for example, `cargo`).
14261428

1427-
Use the placeholders `${package}`, `${target_arg}`, `${target}` to dynamically replace the package name,
1428-
target option (such as `--bin` or `--example`), and the target name.
1429+
Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${test_name}` to dynamically
1430+
replace the package name, target option (such as `--bin` or `--example`), the target name and
1431+
the test name (name of test function or test mod path).
14291432

14301433

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

editors/code/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2840,7 +2840,7 @@
28402840
"title": "Runnables",
28412841
"properties": {
28422842
"rust-analyzer.runnables.bench.overrideCommand": {
2843-
"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}` to dynamically replace the package name,\ntarget option (such as `--bin` or `--example`), and the target name.",
2843+
"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}`, `${test_name}` to dynamically\nreplace the package name, target option (such as `--bin` or `--example`), the target name and\nthe test name (name of test function or test mod path).",
28442844
"default": null,
28452845
"type": [
28462846
"null",
@@ -2869,7 +2869,7 @@
28692869
"title": "Runnables",
28702870
"properties": {
28712871
"rust-analyzer.runnables.doctest.overrideCommand": {
2872-
"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}` to dynamically replace the package name,\ntarget option (such as `--bin` or `--example`), and the target name.",
2872+
"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}`, `${test_name}` to dynamically\nreplace the package name, target option (such as `--bin` or `--example`), the target name and\nthe test name (name of test function or test mod path).",
28732873
"default": null,
28742874
"type": [
28752875
"null",
@@ -2923,7 +2923,7 @@
29232923
"title": "Runnables",
29242924
"properties": {
29252925
"rust-analyzer.runnables.test.overrideCommand": {
2926-
"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}` to dynamically replace the package name,\ntarget option (such as `--bin` or `--example`), and the target name.",
2926+
"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}`, `${test_name}` to dynamically\nreplace the package name, target option (such as `--bin` or `--example`), the target name and\nthe test name (name of test function or test mod path).",
29272927
"default": null,
29282928
"type": [
29292929
"null",

0 commit comments

Comments
 (0)