Skip to content

Commit 03135d8

Browse files
committed
feat: implement configuration to change subcommand for test and bench
1 parent 9581ba4 commit 03135d8

File tree

4 files changed

+114
-6
lines changed

4 files changed

+114
-6
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,10 @@ config_data! {
908908
/// This config takes a map of crate names with the exported proc-macro names to ignore as values.
909909
procMacro_ignored: FxHashMap<Box<str>, Box<[Box<str>]>> = FxHashMap::default(),
910910

911+
/// Subcommand used for bench runnables instead of `bench`.
912+
runnables_bench_command: String = "bench".to_owned(),
913+
/// Override the subcommand used for bench runnables.
914+
runnables_bench_overrideCommand: Option<Vec<String>> = None,
911915
/// Command to be executed instead of 'cargo' for runnables.
912916
runnables_command: Option<String> = None,
913917
/// Additional arguments to be passed to cargo for runnables such as
@@ -921,6 +925,10 @@ config_data! {
921925
/// they will end up being interpreted as options to
922926
/// [`rustc`’s built-in test harness (“libtest”)](https://doc.rust-lang.org/rustc/tests/index.html#cli-arguments).
923927
runnables_extraTestBinaryArgs: Vec<String> = vec!["--nocapture".to_owned()],
928+
/// Subcommand used for test runnables instead of `test`.
929+
runnables_test_command: String = "test".to_owned(),
930+
/// Override the subcommand used for test runnables.
931+
runnables_test_overrideCommand: Option<Vec<String>> = None,
924932

925933
/// Path to the Cargo.toml of the rust compiler workspace, for usage in rustc_private
926934
/// projects, or "discover" to try to automatically find it if the `rustc-dev` component
@@ -1572,6 +1580,14 @@ pub struct RunnablesConfig {
15721580
pub cargo_extra_args: Vec<String>,
15731581
/// Additional arguments for the binary being run, if it is a test or benchmark.
15741582
pub extra_test_binary_args: Vec<String>,
1583+
/// Subcommand used for doctest runnables instead of `test`.
1584+
pub test_command: String,
1585+
/// Override the subcommand used for test runnables.
1586+
pub test_override_command: Option<Vec<String>>,
1587+
/// Subcommand used for doctest runnables instead of `bench`.
1588+
pub bench_command: String,
1589+
/// Override the subcommand used for bench runnables.
1590+
pub bench_override_command: Option<Vec<String>>,
15751591
}
15761592

15771593
/// Configuration for workspace symbol search requests.
@@ -2499,6 +2515,10 @@ impl Config {
24992515
override_cargo: self.runnables_command(source_root).clone(),
25002516
cargo_extra_args: self.runnables_extraArgs(source_root).clone(),
25012517
extra_test_binary_args: self.runnables_extraTestBinaryArgs(source_root).clone(),
2518+
test_command: self.runnables_test_command(source_root).clone(),
2519+
test_override_command: self.runnables_test_overrideCommand(source_root).clone(),
2520+
bench_command: self.runnables_bench_command(source_root).clone(),
2521+
bench_override_command: self.runnables_bench_overrideCommand(source_root).clone(),
25022522
}
25032523
}
25042524

crates/rust-analyzer/src/target_spec.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ impl CargoTargetSpec {
123123

124124
match kind {
125125
RunnableKind::Test { test_id, attr } => {
126-
cargo_args.push("test".to_owned());
126+
let subcommand =
127+
config.test_override_command.unwrap_or_else(|| vec![config.test_command]);
128+
cargo_args.extend(subcommand);
127129
executable_args.push(test_id.to_string());
128130
if let TestId::Path(_) = test_id {
129131
executable_args.push("--exact".to_owned());
@@ -134,12 +136,16 @@ impl CargoTargetSpec {
134136
}
135137
}
136138
RunnableKind::TestMod { path } => {
137-
cargo_args.push("test".to_owned());
139+
let subcommand =
140+
config.test_override_command.unwrap_or_else(|| vec![config.test_command]);
141+
cargo_args.extend(subcommand);
138142
executable_args.push(path.clone());
139143
executable_args.extend(extra_test_binary_args);
140144
}
141145
RunnableKind::Bench { test_id } => {
142-
cargo_args.push("bench".to_owned());
146+
let subcommand =
147+
config.bench_override_command.unwrap_or_else(|| vec![config.bench_command]);
148+
cargo_args.extend(subcommand);
143149
executable_args.push(test_id.to_string());
144150
if let TestId::Path(_) = test_id {
145151
executable_args.push("--exact".to_owned());
@@ -154,10 +160,12 @@ impl CargoTargetSpec {
154160
}
155161
RunnableKind::Bin => {
156162
let subcommand = match spec {
157-
Some(CargoTargetSpec { target_kind: TargetKind::Test, .. }) => "test",
158-
_ => "run",
163+
Some(CargoTargetSpec { target_kind: TargetKind::Test, .. }) => {
164+
config.test_override_command.unwrap_or_else(|| vec![config.test_command])
165+
}
166+
_ => vec!["run".to_owned()],
159167
};
160-
cargo_args.push(subcommand.to_owned());
168+
cargo_args.extend(subcommand);
161169
}
162170
}
163171

docs/book/src/configuration_generated.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,20 @@ Default: `false`
13521352
Exclude tests from find-all-references and call-hierarchy.
13531353

13541354

1355+
## rust-analyzer.runnables.bench.command {#runnables.bench.command}
1356+
1357+
Default: `"bench"`
1358+
1359+
Subcommand used for bench runnables instead of `bench`.
1360+
1361+
1362+
## rust-analyzer.runnables.bench.overrideCommand {#runnables.bench.overrideCommand}
1363+
1364+
Default: `null`
1365+
1366+
Override the subcommand used for bench runnables.
1367+
1368+
13551369
## rust-analyzer.runnables.command {#runnables.command}
13561370

13571371
Default: `null`
@@ -1385,6 +1399,20 @@ they will end up being interpreted as options to
13851399
[`rustc`’s built-in test harness (“libtest”)](https://doc.rust-lang.org/rustc/tests/index.html#cli-arguments).
13861400

13871401

1402+
## rust-analyzer.runnables.test.command {#runnables.test.command}
1403+
1404+
Default: `"test"`
1405+
1406+
Subcommand used for test runnables instead of `test`.
1407+
1408+
1409+
## rust-analyzer.runnables.test.overrideCommand {#runnables.test.overrideCommand}
1410+
1411+
Default: `null`
1412+
1413+
Override the subcommand used for test runnables.
1414+
1415+
13881416
## rust-analyzer.rustc.source {#rustc.source}
13891417

13901418
Default: `null`

editors/code/package.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2827,6 +2827,32 @@
28272827
}
28282828
}
28292829
},
2830+
{
2831+
"title": "Runnables",
2832+
"properties": {
2833+
"rust-analyzer.runnables.bench.command": {
2834+
"markdownDescription": "Subcommand used for bench runnables instead of `bench`.",
2835+
"default": "bench",
2836+
"type": "string"
2837+
}
2838+
}
2839+
},
2840+
{
2841+
"title": "Runnables",
2842+
"properties": {
2843+
"rust-analyzer.runnables.bench.overrideCommand": {
2844+
"markdownDescription": "Override the subcommand used for bench runnables.",
2845+
"default": null,
2846+
"type": [
2847+
"null",
2848+
"array"
2849+
],
2850+
"items": {
2851+
"type": "string"
2852+
}
2853+
}
2854+
}
2855+
},
28302856
{
28312857
"title": "Runnables",
28322858
"properties": {
@@ -2868,6 +2894,32 @@
28682894
}
28692895
}
28702896
},
2897+
{
2898+
"title": "Runnables",
2899+
"properties": {
2900+
"rust-analyzer.runnables.test.command": {
2901+
"markdownDescription": "Subcommand used for test runnables instead of `test`.",
2902+
"default": "test",
2903+
"type": "string"
2904+
}
2905+
}
2906+
},
2907+
{
2908+
"title": "Runnables",
2909+
"properties": {
2910+
"rust-analyzer.runnables.test.overrideCommand": {
2911+
"markdownDescription": "Override the subcommand used for test runnables.",
2912+
"default": null,
2913+
"type": [
2914+
"null",
2915+
"array"
2916+
],
2917+
"items": {
2918+
"type": "string"
2919+
}
2920+
}
2921+
}
2922+
},
28712923
{
28722924
"title": "Rustc",
28732925
"properties": {

0 commit comments

Comments
 (0)