Skip to content

Commit 956e192

Browse files
committed
feat: config for commands and args for test, bench and doctest runnables
1 parent 97e140f commit 956e192

File tree

4 files changed

+110
-57
lines changed

4 files changed

+110
-57
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -908,12 +908,16 @@ 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()],
911+
/// Arguments to passed for bench runnables.
912+
runnables_bench_args: Vec<String> = vec![],
913+
/// Subcommand used for bench runnables insted of `bench`.
914+
runnables_bench_command: String = "bench".to_owned(),
913915
/// Command to be executed instead of 'cargo' for runnables.
914916
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()],
917+
/// Arguments to passed for doctest runnables.
918+
runnables_doctest_args: Vec<String> = vec!["--doc".to_owned()],
919+
/// Subcommand used for doctest runnables insted of `test`.
920+
runnables_doctest_command: String = "test".to_owned(),
917921
/// Additional arguments to be passed to cargo for runnables such as
918922
/// tests or binaries. For example, it may be `--release`.
919923
runnables_extraArgs: Vec<String> = vec![],
@@ -925,8 +929,10 @@ config_data! {
925929
/// they will end up being interpreted as options to
926930
/// [`rustc`’s built-in test harness (“libtest”)](https://doc.rust-lang.org/rustc/tests/index.html#cli-arguments).
927931
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()],
932+
/// Arguments to passed for test runnables.
933+
runnables_test_args: Vec<String> = vec![],
934+
/// Subcommand used for test runnables insted of `test`.
935+
runnables_test_command: String = "test".to_owned(),
930936

931937
/// Path to the Cargo.toml of the rust compiler workspace, for usage in rustc_private
932938
/// projects, or "discover" to try to automatically find it if the `rustc-dev` component
@@ -1578,12 +1584,18 @@ pub struct RunnablesConfig {
15781584
pub cargo_extra_args: Vec<String>,
15791585
/// Additional arguments for the binary being run, if it is a test or benchmark.
15801586
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>,
1587+
/// Subcommand used for doctest runnables insted of `test`.
1588+
pub test_command: String,
1589+
/// Arguments to passed for test runnables.
1590+
pub test_args: Vec<String>,
1591+
/// Subcommand used for doctest runnables insted of `bench`.
1592+
pub bench_command: String,
1593+
/// Arguments to passed for bench runnables.
1594+
pub bench_args: Vec<String>,
1595+
/// Subcommand used for doctest runnables insted of `test`.
1596+
pub doctest_command: String,
1597+
/// Arguments to passed for doctest runnables.
1598+
pub doctest_args: Vec<String>,
15871599
}
15881600

15891601
/// Configuration for workspace symbol search requests.
@@ -2511,11 +2523,12 @@ impl Config {
25112523
override_cargo: self.runnables_command(source_root).clone(),
25122524
cargo_extra_args: self.runnables_extraArgs(source_root).clone(),
25132525
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(),
2526+
test_command: self.runnables_test_command(source_root).clone(),
2527+
test_args: self.runnables_test_args(source_root).clone(),
2528+
bench_command: self.runnables_bench_command(source_root).clone(),
2529+
bench_args: self.runnables_bench_args(source_root).clone(),
2530+
doctest_command: self.runnables_doctest_command(source_root).clone(),
2531+
doctest_args: self.runnables_doctest_args(source_root).clone(),
25192532
}
25202533
}
25212534

crates/rust-analyzer/src/target_spec.rs

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

124124
match kind {
125125
RunnableKind::Test { test_id, attr } => {
126-
cargo_args.extend(config.override_subcommand_test);
126+
cargo_args.push(config.test_command);
127+
cargo_args.extend(config.test_args);
127128
executable_args.push(test_id.to_string());
128129
if let TestId::Path(_) = test_id {
129130
executable_args.push("--exact".to_owned());
@@ -134,31 +135,35 @@ impl CargoTargetSpec {
134135
}
135136
}
136137
RunnableKind::TestMod { path } => {
137-
cargo_args.extend(config.override_subcommand_test);
138+
cargo_args.push(config.test_command);
139+
cargo_args.extend(config.test_args);
138140
executable_args.push(path.clone());
139141
executable_args.extend(extra_test_binary_args);
140142
}
141143
RunnableKind::Bench { test_id } => {
142-
cargo_args.extend(config.override_subcommand_bench);
144+
cargo_args.push(config.bench_command);
145+
cargo_args.extend(config.bench_args);
143146
executable_args.push(test_id.to_string());
144147
if let TestId::Path(_) = test_id {
145148
executable_args.push("--exact".to_owned());
146149
}
147150
executable_args.extend(extra_test_binary_args);
148151
}
149152
RunnableKind::DocTest { test_id } => {
150-
cargo_args.extend(config.override_subcommand_doctest);
153+
cargo_args.push(config.doctest_command);
154+
cargo_args.extend(config.doctest_args);
151155
executable_args.push(test_id.to_string());
152156
executable_args.extend(extra_test_binary_args);
153157
}
154158
RunnableKind::Bin => {
155-
let subcommand = match spec {
159+
let (subcommand, args) = match spec {
156160
Some(CargoTargetSpec { target_kind: TargetKind::Test, .. }) => {
157-
config.override_subcommand_test
161+
(config.test_command, Some(config.test_args))
158162
}
159-
_ => vec!["run".to_owned()],
163+
_ => ("run".to_owned(), None),
160164
};
161-
cargo_args.extend(subcommand);
165+
cargo_args.push(subcommand);
166+
cargo_args.extend(args.unwrap_or_default());
162167
}
163168
}
164169

docs/book/src/configuration_generated.md

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,16 +1352,18 @@ Default: `false`
13521352
Exclude tests from find-all-references and call-hierarchy.
13531353

13541354

1355-
## rust-analyzer.runnables.bench.overrideCommand {#runnables.bench.overrideCommand}
1355+
## rust-analyzer.runnables.bench.args {#runnables.bench.args}
13561356

1357-
Default:
1358-
```json
1359-
[
1360-
"bench"
1361-
]
1362-
```
1357+
Default: `[]`
13631358

1364-
Override the subcommand used for bench runnables.
1359+
Arguments to passed for bench runnables.
1360+
1361+
1362+
## rust-analyzer.runnables.bench.command {#runnables.bench.command}
1363+
1364+
Default: `"bench"`
1365+
1366+
Subcommand used for bench runnables insted of `bench`.
13651367

13661368

13671369
## rust-analyzer.runnables.command {#runnables.command}
@@ -1371,17 +1373,23 @@ Default: `null`
13711373
Command to be executed instead of 'cargo' for runnables.
13721374

13731375

1374-
## rust-analyzer.runnables.doctest.overrideCommand {#runnables.doctest.overrideCommand}
1376+
## rust-analyzer.runnables.doctest.args {#runnables.doctest.args}
13751377

13761378
Default:
13771379
```json
13781380
[
1379-
"test",
13801381
"--doc"
13811382
]
13821383
```
13831384

1384-
Override the subcommand used for doc test runnables.
1385+
Arguments to passed for doctest runnables.
1386+
1387+
1388+
## rust-analyzer.runnables.doctest.command {#runnables.doctest.command}
1389+
1390+
Default: `"test"`
1391+
1392+
Subcommand used for doctest runnables insted of `test`.
13851393

13861394

13871395
## rust-analyzer.runnables.extraArgs {#runnables.extraArgs}
@@ -1410,16 +1418,18 @@ they will end up being interpreted as options to
14101418
[`rustc`’s built-in test harness (“libtest”)](https://doc.rust-lang.org/rustc/tests/index.html#cli-arguments).
14111419

14121420

1413-
## rust-analyzer.runnables.test.overrideCommand {#runnables.test.overrideCommand}
1421+
## rust-analyzer.runnables.test.args {#runnables.test.args}
14141422

1415-
Default:
1416-
```json
1417-
[
1418-
"test"
1419-
]
1420-
```
1423+
Default: `[]`
1424+
1425+
Arguments to passed for test runnables.
1426+
1427+
1428+
## rust-analyzer.runnables.test.command {#runnables.test.command}
1429+
1430+
Default: `"test"`
14211431

1422-
Override the subcommand used for test runnables.
1432+
Subcommand used for test runnables insted of `test`.
14231433

14241434

14251435
## rust-analyzer.rustc.source {#rustc.source}

editors/code/package.json

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2825,18 +2825,26 @@
28252825
{
28262826
"title": "Runnables",
28272827
"properties": {
2828-
"rust-analyzer.runnables.bench.overrideCommand": {
2829-
"markdownDescription": "Override the subcommand used for bench runnables.",
2830-
"default": [
2831-
"bench"
2832-
],
2828+
"rust-analyzer.runnables.bench.args": {
2829+
"markdownDescription": "Arguments to passed for bench runnables.",
2830+
"default": [],
28332831
"type": "array",
28342832
"items": {
28352833
"type": "string"
28362834
}
28372835
}
28382836
}
28392837
},
2838+
{
2839+
"title": "Runnables",
2840+
"properties": {
2841+
"rust-analyzer.runnables.bench.command": {
2842+
"markdownDescription": "Subcommand used for bench runnables insted of `bench`.",
2843+
"default": "bench",
2844+
"type": "string"
2845+
}
2846+
}
2847+
},
28402848
{
28412849
"title": "Runnables",
28422850
"properties": {
@@ -2853,10 +2861,9 @@
28532861
{
28542862
"title": "Runnables",
28552863
"properties": {
2856-
"rust-analyzer.runnables.doctest.overrideCommand": {
2857-
"markdownDescription": "Override the subcommand used for doc test runnables.",
2864+
"rust-analyzer.runnables.doctest.args": {
2865+
"markdownDescription": "Arguments to passed for doctest runnables.",
28582866
"default": [
2859-
"test",
28602867
"--doc"
28612868
],
28622869
"type": "array",
@@ -2866,6 +2873,16 @@
28662873
}
28672874
}
28682875
},
2876+
{
2877+
"title": "Runnables",
2878+
"properties": {
2879+
"rust-analyzer.runnables.doctest.command": {
2880+
"markdownDescription": "Subcommand used for doctest runnables insted of `test`.",
2881+
"default": "test",
2882+
"type": "string"
2883+
}
2884+
}
2885+
},
28692886
{
28702887
"title": "Runnables",
28712888
"properties": {
@@ -2897,18 +2914,26 @@
28972914
{
28982915
"title": "Runnables",
28992916
"properties": {
2900-
"rust-analyzer.runnables.test.overrideCommand": {
2901-
"markdownDescription": "Override the subcommand used for test runnables.",
2902-
"default": [
2903-
"test"
2904-
],
2917+
"rust-analyzer.runnables.test.args": {
2918+
"markdownDescription": "Arguments to passed for test runnables.",
2919+
"default": [],
29052920
"type": "array",
29062921
"items": {
29072922
"type": "string"
29082923
}
29092924
}
29102925
}
29112926
},
2927+
{
2928+
"title": "Runnables",
2929+
"properties": {
2930+
"rust-analyzer.runnables.test.command": {
2931+
"markdownDescription": "Subcommand used for test runnables insted of `test`.",
2932+
"default": "test",
2933+
"type": "string"
2934+
}
2935+
}
2936+
},
29122937
{
29132938
"title": "Rustc",
29142939
"properties": {

0 commit comments

Comments
 (0)