Skip to content

Commit 97e140f

Browse files
committed
feat: implement configuration to change sub command for test, bench and doctest
1 parent fa4ea90 commit 97e140f

File tree

4 files changed

+109
-8
lines changed

4 files changed

+109
-8
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,8 +908,12 @@ 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+
/// Override the subcommand used for bench runnables.
912+
runnables_bench_overrideCommand: Vec<String> = vec!["bench".to_owned()],
911913
/// Command to be executed instead of 'cargo' for runnables.
912914
runnables_command: Option<String> = None,
915+
/// Override the subcommand used for doc test runnables.
916+
runnables_doctest_overrideCommand: Vec<String> = vec!["test".to_owned(), "--doc".to_owned()],
913917
/// Additional arguments to be passed to cargo for runnables such as
914918
/// tests or binaries. For example, it may be `--release`.
915919
runnables_extraArgs: Vec<String> = vec![],
@@ -921,6 +925,8 @@ 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+
/// Override the subcommand used for test runnables.
929+
runnables_test_overrideCommand: Vec<String> = vec!["test".to_owned()],
924930

925931
/// Path to the Cargo.toml of the rust compiler workspace, for usage in rustc_private
926932
/// projects, or "discover" to try to automatically find it if the `rustc-dev` component
@@ -1572,6 +1578,12 @@ pub struct RunnablesConfig {
15721578
pub cargo_extra_args: Vec<String>,
15731579
/// Additional arguments for the binary being run, if it is a test or benchmark.
15741580
pub extra_test_binary_args: Vec<String>,
1581+
/// Override subcommand to be used for test runnables.
1582+
pub override_subcommand_test: Vec<String>,
1583+
/// Override subcommand to be used for bench runnables.
1584+
pub override_subcommand_bench: Vec<String>,
1585+
/// Override subcommand to be used for doc test runnables.
1586+
pub override_subcommand_doctest: Vec<String>,
15751587
}
15761588

15771589
/// Configuration for workspace symbol search requests.
@@ -2499,6 +2511,11 @@ impl Config {
24992511
override_cargo: self.runnables_command(source_root).clone(),
25002512
cargo_extra_args: self.runnables_extraArgs(source_root).clone(),
25012513
extra_test_binary_args: self.runnables_extraTestBinaryArgs(source_root).clone(),
2514+
override_subcommand_test: self.runnables_test_overrideCommand(source_root).clone(),
2515+
override_subcommand_bench: self.runnables_bench_overrideCommand(source_root).clone(),
2516+
override_subcommand_doctest: self
2517+
.runnables_doctest_overrideCommand(source_root)
2518+
.clone(),
25022519
}
25032520
}
25042521

crates/rust-analyzer/src/target_spec.rs

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

124124
match kind {
125125
RunnableKind::Test { test_id, attr } => {
126-
cargo_args.push("test".to_owned());
126+
cargo_args.extend(config.override_subcommand_test);
127127
executable_args.push(test_id.to_string());
128128
if let TestId::Path(_) = test_id {
129129
executable_args.push("--exact".to_owned());
@@ -134,30 +134,31 @@ impl CargoTargetSpec {
134134
}
135135
}
136136
RunnableKind::TestMod { path } => {
137-
cargo_args.push("test".to_owned());
137+
cargo_args.extend(config.override_subcommand_test);
138138
executable_args.push(path.clone());
139139
executable_args.extend(extra_test_binary_args);
140140
}
141141
RunnableKind::Bench { test_id } => {
142-
cargo_args.push("bench".to_owned());
142+
cargo_args.extend(config.override_subcommand_bench);
143143
executable_args.push(test_id.to_string());
144144
if let TestId::Path(_) = test_id {
145145
executable_args.push("--exact".to_owned());
146146
}
147147
executable_args.extend(extra_test_binary_args);
148148
}
149149
RunnableKind::DocTest { test_id } => {
150-
cargo_args.push("test".to_owned());
151-
cargo_args.push("--doc".to_owned());
150+
cargo_args.extend(config.override_subcommand_doctest);
152151
executable_args.push(test_id.to_string());
153152
executable_args.extend(extra_test_binary_args);
154153
}
155154
RunnableKind::Bin => {
156155
let subcommand = match spec {
157-
Some(CargoTargetSpec { target_kind: TargetKind::Test, .. }) => "test",
158-
_ => "run",
156+
Some(CargoTargetSpec { target_kind: TargetKind::Test, .. }) => {
157+
config.override_subcommand_test
158+
}
159+
_ => vec!["run".to_owned()],
159160
};
160-
cargo_args.push(subcommand.to_owned());
161+
cargo_args.extend(subcommand);
161162
}
162163
}
163164

docs/book/src/configuration_generated.md

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

13541354

1355+
## rust-analyzer.runnables.bench.overrideCommand {#runnables.bench.overrideCommand}
1356+
1357+
Default:
1358+
```json
1359+
[
1360+
"bench"
1361+
]
1362+
```
1363+
1364+
Override the subcommand used for bench runnables.
1365+
1366+
13551367
## rust-analyzer.runnables.command {#runnables.command}
13561368

13571369
Default: `null`
13581370

13591371
Command to be executed instead of 'cargo' for runnables.
13601372

13611373

1374+
## rust-analyzer.runnables.doctest.overrideCommand {#runnables.doctest.overrideCommand}
1375+
1376+
Default:
1377+
```json
1378+
[
1379+
"test",
1380+
"--doc"
1381+
]
1382+
```
1383+
1384+
Override the subcommand used for doc test runnables.
1385+
1386+
13621387
## rust-analyzer.runnables.extraArgs {#runnables.extraArgs}
13631388

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

13871412

1413+
## rust-analyzer.runnables.test.overrideCommand {#runnables.test.overrideCommand}
1414+
1415+
Default:
1416+
```json
1417+
[
1418+
"test"
1419+
]
1420+
```
1421+
1422+
Override the subcommand used for test runnables.
1423+
1424+
13881425
## rust-analyzer.rustc.source {#rustc.source}
13891426

13901427
Default: `null`

editors/code/package.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2822,6 +2822,21 @@
28222822
}
28232823
}
28242824
},
2825+
{
2826+
"title": "Runnables",
2827+
"properties": {
2828+
"rust-analyzer.runnables.bench.overrideCommand": {
2829+
"markdownDescription": "Override the subcommand used for bench runnables.",
2830+
"default": [
2831+
"bench"
2832+
],
2833+
"type": "array",
2834+
"items": {
2835+
"type": "string"
2836+
}
2837+
}
2838+
}
2839+
},
28252840
{
28262841
"title": "Runnables",
28272842
"properties": {
@@ -2835,6 +2850,22 @@
28352850
}
28362851
}
28372852
},
2853+
{
2854+
"title": "Runnables",
2855+
"properties": {
2856+
"rust-analyzer.runnables.doctest.overrideCommand": {
2857+
"markdownDescription": "Override the subcommand used for doc test runnables.",
2858+
"default": [
2859+
"test",
2860+
"--doc"
2861+
],
2862+
"type": "array",
2863+
"items": {
2864+
"type": "string"
2865+
}
2866+
}
2867+
}
2868+
},
28382869
{
28392870
"title": "Runnables",
28402871
"properties": {
@@ -2863,6 +2894,21 @@
28632894
}
28642895
}
28652896
},
2897+
{
2898+
"title": "Runnables",
2899+
"properties": {
2900+
"rust-analyzer.runnables.test.overrideCommand": {
2901+
"markdownDescription": "Override the subcommand used for test runnables.",
2902+
"default": [
2903+
"test"
2904+
],
2905+
"type": "array",
2906+
"items": {
2907+
"type": "string"
2908+
}
2909+
}
2910+
}
2911+
},
28662912
{
28672913
"title": "Rustc",
28682914
"properties": {

0 commit comments

Comments
 (0)