diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 2371f7a65649..a3add368276f 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -908,6 +908,10 @@ config_data! { /// This config takes a map of crate names with the exported proc-macro names to ignore as values. procMacro_ignored: FxHashMap, Box<[Box]>> = FxHashMap::default(), + /// Subcommand used for bench runnables instead of `bench`. + runnables_bench_command: String = "bench".to_owned(), + /// Override the subcommand used for bench runnables. + runnables_bench_overrideCommand: Option> = None, /// Command to be executed instead of 'cargo' for runnables. runnables_command: Option = None, /// Additional arguments to be passed to cargo for runnables such as @@ -921,6 +925,10 @@ config_data! { /// they will end up being interpreted as options to /// [`rustc`’s built-in test harness (“libtest”)](https://doc.rust-lang.org/rustc/tests/index.html#cli-arguments). runnables_extraTestBinaryArgs: Vec = vec!["--nocapture".to_owned()], + /// Subcommand used for test runnables instead of `test`. + runnables_test_command: String = "test".to_owned(), + /// Override the subcommand used for test runnables. + runnables_test_overrideCommand: Option> = None, /// Path to the Cargo.toml of the rust compiler workspace, for usage in rustc_private /// projects, or "discover" to try to automatically find it if the `rustc-dev` component @@ -1572,6 +1580,14 @@ pub struct RunnablesConfig { pub cargo_extra_args: Vec, /// Additional arguments for the binary being run, if it is a test or benchmark. pub extra_test_binary_args: Vec, + /// Subcommand used for doctest runnables instead of `test`. + pub test_command: String, + /// Override the subcommand used for test runnables. + pub test_override_command: Option>, + /// Subcommand used for doctest runnables instead of `bench`. + pub bench_command: String, + /// Override the subcommand used for bench runnables. + pub bench_override_command: Option>, } /// Configuration for workspace symbol search requests. @@ -2499,6 +2515,10 @@ impl Config { override_cargo: self.runnables_command(source_root).clone(), cargo_extra_args: self.runnables_extraArgs(source_root).clone(), extra_test_binary_args: self.runnables_extraTestBinaryArgs(source_root).clone(), + test_command: self.runnables_test_command(source_root).clone(), + test_override_command: self.runnables_test_overrideCommand(source_root).clone(), + bench_command: self.runnables_bench_command(source_root).clone(), + bench_override_command: self.runnables_bench_overrideCommand(source_root).clone(), } } diff --git a/crates/rust-analyzer/src/target_spec.rs b/crates/rust-analyzer/src/target_spec.rs index e532d155536c..d1e3c4adf6f9 100644 --- a/crates/rust-analyzer/src/target_spec.rs +++ b/crates/rust-analyzer/src/target_spec.rs @@ -123,7 +123,9 @@ impl CargoTargetSpec { match kind { RunnableKind::Test { test_id, attr } => { - cargo_args.push("test".to_owned()); + let subcommand = + config.test_override_command.unwrap_or_else(|| vec![config.test_command]); + cargo_args.extend(subcommand); executable_args.push(test_id.to_string()); if let TestId::Path(_) = test_id { executable_args.push("--exact".to_owned()); @@ -134,12 +136,16 @@ impl CargoTargetSpec { } } RunnableKind::TestMod { path } => { - cargo_args.push("test".to_owned()); + let subcommand = + config.test_override_command.unwrap_or_else(|| vec![config.test_command]); + cargo_args.extend(subcommand); executable_args.push(path.clone()); executable_args.extend(extra_test_binary_args); } RunnableKind::Bench { test_id } => { - cargo_args.push("bench".to_owned()); + let subcommand = + config.bench_override_command.unwrap_or_else(|| vec![config.bench_command]); + cargo_args.extend(subcommand); executable_args.push(test_id.to_string()); if let TestId::Path(_) = test_id { executable_args.push("--exact".to_owned()); @@ -154,10 +160,12 @@ impl CargoTargetSpec { } RunnableKind::Bin => { let subcommand = match spec { - Some(CargoTargetSpec { target_kind: TargetKind::Test, .. }) => "test", - _ => "run", + Some(CargoTargetSpec { target_kind: TargetKind::Test, .. }) => { + config.test_override_command.unwrap_or_else(|| vec![config.test_command]) + } + _ => vec!["run".to_owned()], }; - cargo_args.push(subcommand.to_owned()); + cargo_args.extend(subcommand); } } diff --git a/docs/book/src/configuration_generated.md b/docs/book/src/configuration_generated.md index 6b7ef049645c..6710060252b9 100644 --- a/docs/book/src/configuration_generated.md +++ b/docs/book/src/configuration_generated.md @@ -1352,6 +1352,20 @@ Default: `false` Exclude tests from find-all-references and call-hierarchy. +## rust-analyzer.runnables.bench.command {#runnables.bench.command} + +Default: `"bench"` + +Subcommand used for bench runnables instead of `bench`. + + +## rust-analyzer.runnables.bench.overrideCommand {#runnables.bench.overrideCommand} + +Default: `null` + +Override the subcommand used for bench runnables. + + ## rust-analyzer.runnables.command {#runnables.command} Default: `null` @@ -1385,6 +1399,20 @@ they will end up being interpreted as options to [`rustc`’s built-in test harness (“libtest”)](https://doc.rust-lang.org/rustc/tests/index.html#cli-arguments). +## rust-analyzer.runnables.test.command {#runnables.test.command} + +Default: `"test"` + +Subcommand used for test runnables instead of `test`. + + +## rust-analyzer.runnables.test.overrideCommand {#runnables.test.overrideCommand} + +Default: `null` + +Override the subcommand used for test runnables. + + ## rust-analyzer.rustc.source {#rustc.source} Default: `null` diff --git a/editors/code/package.json b/editors/code/package.json index 97db1322dd71..b0e356ed5186 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -2822,6 +2822,32 @@ } } }, + { + "title": "Runnables", + "properties": { + "rust-analyzer.runnables.bench.command": { + "markdownDescription": "Subcommand used for bench runnables instead of `bench`.", + "default": "bench", + "type": "string" + } + } + }, + { + "title": "Runnables", + "properties": { + "rust-analyzer.runnables.bench.overrideCommand": { + "markdownDescription": "Override the subcommand used for bench runnables.", + "default": null, + "type": [ + "null", + "array" + ], + "items": { + "type": "string" + } + } + } + }, { "title": "Runnables", "properties": { @@ -2863,6 +2889,32 @@ } } }, + { + "title": "Runnables", + "properties": { + "rust-analyzer.runnables.test.command": { + "markdownDescription": "Subcommand used for test runnables instead of `test`.", + "default": "test", + "type": "string" + } + } + }, + { + "title": "Runnables", + "properties": { + "rust-analyzer.runnables.test.overrideCommand": { + "markdownDescription": "Override the subcommand used for test runnables.", + "default": null, + "type": [ + "null", + "array" + ], + "items": { + "type": "string" + } + } + } + }, { "title": "Rustc", "properties": {