Unnamed repository; edit this file 'description' to name the repository.
Merge pull request #21395 from dfireBird/push-sqrmpnzrzwpt
feat: change test_name placeholder to executable_arg
Chayim Refael Friedman 8 weeks ago
parent 12ea8a2 · parent a308ce5 · commit 98fd321
-rw-r--r--crates/rust-analyzer/src/config.rs12
-rw-r--r--crates/rust-analyzer/src/target_spec.rs85
-rw-r--r--docs/book/src/configuration_generated.md12
-rw-r--r--editors/code/package.json6
4 files changed, 76 insertions, 39 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 0dda7f3cc2..2ccd85f0e3 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -948,18 +948,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}`, `${test_name}` to dynamically
+ /// Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${executable_args}` 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).
+ /// the arguments passed to test binary args (includes `rust-analyzer.runnables.extraTestBinaryArgs`).
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}`, `${test_name}` to dynamically
+ /// Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${executable_args}` 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).
+ /// the arguments passed to test binary args (includes `rust-analyzer.runnables.extraTestBinaryArgs`).
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`.
@@ -977,9 +977,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}`, `${test_name}` to dynamically
+ /// Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${executable_args}` 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).
+ /// the arguments passed to test binary args (includes `rust-analyzer.runnables.extraTestBinaryArgs`).
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/target_spec.rs b/crates/rust-analyzer/src/target_spec.rs
index b8d9acc02a..811c0a0c11 100644
--- a/crates/rust-analyzer/src/target_spec.rs
+++ b/crates/rust-analyzer/src/target_spec.rs
@@ -129,38 +129,21 @@ impl CargoTargetSpec {
let extra_test_binary_args = config.extra_test_binary_args;
let mut cargo_args = Vec::new();
- let mut executable_args = Vec::new();
+ let executable_args = Self::executable_args_for(kind, extra_test_binary_args);
match kind {
- RunnableKind::Test { test_id, attr } => {
+ RunnableKind::Test { .. } => {
cargo_args.push(config.test_command);
- executable_args.push(test_id.to_string());
- if let TestId::Path(_) = test_id {
- executable_args.push("--exact".to_owned());
- }
- executable_args.extend(extra_test_binary_args);
- if attr.ignore {
- executable_args.push("--ignored".to_owned());
- }
}
- RunnableKind::TestMod { path } => {
+ RunnableKind::TestMod { .. } => {
cargo_args.push(config.test_command);
- executable_args.push(path.clone());
- executable_args.extend(extra_test_binary_args);
}
- RunnableKind::Bench { test_id } => {
+ RunnableKind::Bench { .. } => {
cargo_args.push(config.bench_command);
- executable_args.push(test_id.to_string());
- if let TestId::Path(_) = test_id {
- executable_args.push("--exact".to_owned());
- }
- executable_args.extend(extra_test_binary_args);
}
- RunnableKind::DocTest { test_id } => {
+ RunnableKind::DocTest { .. } => {
cargo_args.push("test".to_owned());
cargo_args.push("--doc".to_owned());
- executable_args.push(test_id.to_string());
- executable_args.extend(extra_test_binary_args);
}
RunnableKind::Bin => {
let subcommand = match spec {
@@ -253,16 +236,70 @@ impl CargoTargetSpec {
TargetKind::BuildScript | TargetKind::Other => "",
};
+ let target = |kind, target| match kind {
+ TargetKind::Bin | TargetKind::Test | TargetKind::Bench | TargetKind::Example => target,
+ _ => "",
+ };
+
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("${target}", target(spec.target_kind, &spec.target))
.replace("${test_name}", &test_name),
_ => arg,
};
- args.map(|args| args.into_iter().map(replace_placeholders).collect())
+ let extra_test_binary_args = config.extra_test_binary_args;
+ let executable_args = Self::executable_args_for(kind, extra_test_binary_args);
+
+ args.map(|mut args| {
+ let exec_args_idx = args.iter().position(|a| a == "${executable_args}");
+
+ if let Some(idx) = exec_args_idx {
+ args.splice(idx..idx + 1, executable_args);
+ }
+
+ args.into_iter().map(replace_placeholders).filter(|a| !a.trim().is_empty()).collect()
+ })
+ }
+
+ fn executable_args_for(
+ kind: &RunnableKind,
+ extra_test_binary_args: impl IntoIterator<Item = String>,
+ ) -> Vec<String> {
+ let mut executable_args = Vec::new();
+
+ match kind {
+ RunnableKind::Test { test_id, attr } => {
+ executable_args.push(test_id.to_string());
+ if let TestId::Path(_) = test_id {
+ executable_args.push("--exact".to_owned());
+ }
+ executable_args.extend(extra_test_binary_args);
+ if attr.ignore {
+ executable_args.push("--ignored".to_owned());
+ }
+ }
+ RunnableKind::TestMod { path } => {
+ executable_args.push(path.clone());
+ executable_args.extend(extra_test_binary_args);
+ }
+ RunnableKind::Bench { test_id } => {
+ executable_args.push(test_id.to_string());
+ if let TestId::Path(_) = test_id {
+ executable_args.push("--exact".to_owned());
+ }
+ executable_args.extend(extra_test_binary_args);
+ }
+ RunnableKind::DocTest { test_id } => {
+ executable_args.push(test_id.to_string());
+ executable_args.extend(extra_test_binary_args);
+ }
+ RunnableKind::Bin => {}
+ }
+
+ executable_args
}
pub(crate) fn push_to(self, buf: &mut Vec<String>, kind: &RunnableKind) {
diff --git a/docs/book/src/configuration_generated.md b/docs/book/src/configuration_generated.md
index 8460c2c7d0..35fba5accd 100644
--- a/docs/book/src/configuration_generated.md
+++ b/docs/book/src/configuration_generated.md
@@ -1380,9 +1380,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}`, `${test_name}` to dynamically
+Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${executable_args}` 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).
+the arguments passed to test binary args (includes `rust-analyzer.runnables.extraTestBinaryArgs`).
## rust-analyzer.runnables.command {#runnables.command}
@@ -1399,9 +1399,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}`, `${test_name}` to dynamically
+Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${executable_args}` 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).
+the arguments passed to test binary args (includes `rust-analyzer.runnables.extraTestBinaryArgs`).
## rust-analyzer.runnables.extraArgs {#runnables.extraArgs}
@@ -1444,9 +1444,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}`, `${test_name}` to dynamically
+Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${executable_args}` 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).
+the arguments passed to test binary args (includes `rust-analyzer.runnables.extraTestBinaryArgs`).
## rust-analyzer.rustc.source {#rustc.source}
diff --git a/editors/code/package.json b/editors/code/package.json
index fc20597e88..1dd513c9de 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -2865,7 +2865,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}`, `${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).",
+ "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`).",
"default": null,
"type": [
"null",
@@ -2894,7 +2894,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}`, `${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).",
+ "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`).",
"default": null,
"type": [
"null",
@@ -2948,7 +2948,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}`, `${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).",
+ "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`).",
"default": null,
"type": [
"null",