Skip to content

Commit dc2bb03

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

File tree

3 files changed

+63
-8
lines changed

3 files changed

+63
-8
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,12 @@ config_data! {
913913
/// Additional arguments to be passed to cargo for runnables such as
914914
/// tests or binaries. For example, it may be `--release`.
915915
runnables_extraArgs: Vec<String> = vec![],
916+
/// Override the subcommand used for test runnables.
917+
runnables_test_overrideCommand: Vec<String> = vec!["test".to_owned()],
918+
/// Override the subcommand used for bench runnables.
919+
runnables_bench_overrideCommand: Vec<String> = vec!["bench".to_owned()],
920+
/// Override the subcommand used for doc test runnables.
921+
runnables_doctest_overrideCommand: Vec<String> = vec!["test".to_owned(), "--doc".to_owned()],
916922
/// Additional arguments to be passed through Cargo to launched tests, benchmarks, or
917923
/// doc-tests.
918924
///
@@ -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

editors/code/package.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2863,6 +2863,43 @@
28632863
}
28642864
}
28652865
},
2866+
{
2867+
"title": "Runnables",
2868+
"properties": {
2869+
"rust-analyzer.runnables.test.overrideCommand": {
2870+
"markdownDescription": "Override the subcommand used for test runnables.",
2871+
"default": [
2872+
"test"
2873+
],
2874+
"type": "array"
2875+
}
2876+
}
2877+
},
2878+
{
2879+
"title": "Runnables",
2880+
"properties": {
2881+
"rust-analyzer.runnables.bench.overrideCommand": {
2882+
"markdownDescription": "Override the subcommand used for bench runnables.",
2883+
"default": [
2884+
"bench"
2885+
],
2886+
"type": "array"
2887+
}
2888+
}
2889+
},
2890+
{
2891+
"title": "Runnables",
2892+
"properties": {
2893+
"rust-analyzer.runnables.doctest.overrideCommand": {
2894+
"markdownDescription": "Override the subcommand used for doc test runnables.",
2895+
"default": [
2896+
"test",
2897+
"--doc"
2898+
],
2899+
"type": "array"
2900+
}
2901+
}
2902+
},
28662903
{
28672904
"title": "Rustc",
28682905
"properties": {

0 commit comments

Comments
 (0)