Unnamed repository; edit this file 'description' to name the repository.
chore: add `test_name` placeholder in config
| -rw-r--r-- | crates/rust-analyzer/src/config.rs | 15 | ||||
| -rw-r--r-- | crates/rust-analyzer/src/lsp/to_proto.rs | 2 | ||||
| -rw-r--r-- | crates/rust-analyzer/src/target_spec.rs | 30 | ||||
| -rw-r--r-- | docs/book/src/configuration_generated.md | 15 | ||||
| -rw-r--r-- | editors/code/package.json | 6 |
5 files changed, 41 insertions, 27 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 3ca2e0d300..e39569e108 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -909,16 +909,18 @@ config_data! { /// Override the command used for bench runnables. /// The first element of the array should be the program to execute (for example, `cargo`). /// - /// Use the placeholders `${package}`, `${target_arg}`, `${target}` to dynamically replace the package name, - /// target option (such as `--bin` or `--example`), and the target name. + /// Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${test_name}` to dynamically + /// replace the package name, target option (such as `--bin` or `--example`), the target name and + /// the test name (name of test function or test mod path). runnables_bench_overrideCommand: Option<Vec<String>> = None, /// Command to be executed instead of 'cargo' for runnables. runnables_command: Option<String> = None, /// Override the command used for bench runnables. /// The first element of the array should be the program to execute (for example, `cargo`). /// - /// Use the placeholders `${package}`, `${target_arg}`, `${target}` to dynamically replace the package name, - /// target option (such as `--bin` or `--example`), and the target name. + /// Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${test_name}` to dynamically + /// replace the package name, target option (such as `--bin` or `--example`), the target name and + /// the test name (name of test function or test mod path). runnables_doctest_overrideCommand: Option<Vec<String>> = None, /// Additional arguments to be passed to cargo for runnables such as /// tests or binaries. For example, it may be `--release`. @@ -936,8 +938,9 @@ config_data! { /// Override the command used for test runnables. /// The first element of the array should be the program to execute (for example, `cargo`). /// - /// Use the placeholders `${package}`, `${target_arg}`, `${target}` to dynamically replace the package name, - /// target option (such as `--bin` or `--example`), and the target name. + /// Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${test_name}` to dynamically + /// replace the package name, target option (such as `--bin` or `--example`), the target name and + /// the test name (name of test function or test mod path). runnables_test_overrideCommand: Option<Vec<String>> = None, /// Path to the Cargo.toml of the rust compiler workspace, for usage in rustc_private diff --git a/crates/rust-analyzer/src/lsp/to_proto.rs b/crates/rust-analyzer/src/lsp/to_proto.rs index 64476338b5..6f0f57725f 100644 --- a/crates/rust-analyzer/src/lsp/to_proto.rs +++ b/crates/rust-analyzer/src/lsp/to_proto.rs @@ -1595,7 +1595,7 @@ pub(crate) fn runnable( environment, cwd: cwd.into(), program: program.to_string(), - args: args.iter().cloned().chain(executable_args).collect(), + args: args.to_vec(), }), }), _ => None, diff --git a/crates/rust-analyzer/src/target_spec.rs b/crates/rust-analyzer/src/target_spec.rs index 6d05efd75b..e0f95a7830 100644 --- a/crates/rust-analyzer/src/target_spec.rs +++ b/crates/rust-analyzer/src/target_spec.rs @@ -214,19 +214,25 @@ impl CargoTargetSpec { kind: &RunnableKind, ) -> Option<Vec<String>> { let config = snap.config.runnables(None); - let args = match kind { - RunnableKind::Test { .. } | RunnableKind::TestMod { .. } => { - config.test_override_command + let (args, test_name) = match kind { + RunnableKind::Test { test_id, .. } => { + (config.test_override_command, Some(test_id.to_string())) + } + RunnableKind::TestMod { path } => (config.test_override_command, Some(path.clone())), + RunnableKind::Bench { test_id } => { + (config.bench_override_command, Some(test_id.to_string())) + } + RunnableKind::DocTest { test_id } => { + (config.doc_test_override_command, Some(test_id.to_string())) } - RunnableKind::Bench { .. } => config.bench_override_command, - RunnableKind::DocTest { .. } => config.doc_test_override_command, RunnableKind::Bin => match spec { Some(CargoTargetSpec { target_kind: TargetKind::Test, .. }) => { - config.test_override_command + (config.test_override_command, None) } - _ => None, + _ => (None, None), }, }; + let test_name = test_name.unwrap_or_default(); let target_arg = |kind| match kind { TargetKind::Bin => "--bin", @@ -237,10 +243,12 @@ impl CargoTargetSpec { TargetKind::BuildScript | TargetKind::Other => "", }; - let replace_placeholders = |arg| match &spec { - Some(spec) if arg == "${package}" => spec.package.clone(), - Some(spec) if arg == "${target_arg}" => target_arg(spec.target_kind).to_owned(), - Some(spec) if arg == "${target}" => spec.target.clone(), + let replace_placeholders = |arg: String| match &spec { + Some(spec) => arg + .replace("${package}", &spec.package) + .replace("${target_arg}", target_arg(spec.target_kind)) + .replace("${target}", &spec.target) + .replace("${test_name}", &test_name), _ => arg, }; diff --git a/docs/book/src/configuration_generated.md b/docs/book/src/configuration_generated.md index e824e18854..58b6363345 100644 --- a/docs/book/src/configuration_generated.md +++ b/docs/book/src/configuration_generated.md @@ -1362,8 +1362,9 @@ Default: `null` Override the command used for bench runnables. The first element of the array should be the program to execute (for example, `cargo`). -Use the placeholders `${package}`, `${target_arg}`, `${target}` to dynamically replace the package name, -target option (such as `--bin` or `--example`), and the target name. +Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${test_name}` to dynamically +replace the package name, target option (such as `--bin` or `--example`), the target name and +the test name (name of test function or test mod path). ## rust-analyzer.runnables.command {#runnables.command} @@ -1380,8 +1381,9 @@ Default: `null` Override the command used for bench runnables. The first element of the array should be the program to execute (for example, `cargo`). -Use the placeholders `${package}`, `${target_arg}`, `${target}` to dynamically replace the package name, -target option (such as `--bin` or `--example`), and the target name. +Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${test_name}` to dynamically +replace the package name, target option (such as `--bin` or `--example`), the target name and +the test name (name of test function or test mod path). ## rust-analyzer.runnables.extraArgs {#runnables.extraArgs} @@ -1424,8 +1426,9 @@ Default: `null` Override the command used for test runnables. The first element of the array should be the program to execute (for example, `cargo`). -Use the placeholders `${package}`, `${target_arg}`, `${target}` to dynamically replace the package name, -target option (such as `--bin` or `--example`), and the target name. +Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${test_name}` to dynamically +replace the package name, target option (such as `--bin` or `--example`), the target name and +the test name (name of test function or test mod path). ## rust-analyzer.rustc.source {#rustc.source} diff --git a/editors/code/package.json b/editors/code/package.json index 3940445809..2157cbd486 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -2840,7 +2840,7 @@ "title": "Runnables", "properties": { "rust-analyzer.runnables.bench.overrideCommand": { - "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.", + "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).", "default": null, "type": [ "null", @@ -2869,7 +2869,7 @@ "title": "Runnables", "properties": { "rust-analyzer.runnables.doctest.overrideCommand": { - "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.", + "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).", "default": null, "type": [ "null", @@ -2923,7 +2923,7 @@ "title": "Runnables", "properties": { "rust-analyzer.runnables.test.overrideCommand": { - "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.", + "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).", "default": null, "type": [ "null", |