Skip to content

Commit 174af88

Browse files
committed
feat: Add rust-analyzer.cargo.allTargets to configure passing --all-targets to cargo invocations
1 parent 4b33850 commit 174af88

File tree

5 files changed

+31
-9
lines changed

5 files changed

+31
-9
lines changed

crates/project-model/src/build_scripts.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ impl WorkspaceBuildScripts {
8686
// --all-targets includes tests, benches and examples in addition to the
8787
// default lib and bins. This is an independent concept from the --target
8888
// flag below.
89-
cmd.arg("--all-targets");
89+
if config.all_targets {
90+
cmd.arg("--all-targets");
91+
}
9092

9193
if let Some(target) = &config.target {
9294
cmd.args(["--target", target]);

crates/project-model/src/cargo_workspace.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ impl Default for CargoFeatures {
7676

7777
#[derive(Default, Clone, Debug, PartialEq, Eq)]
7878
pub struct CargoConfig {
79+
/// Whether to pass `--all-targets` to cargo invocations.
80+
pub all_targets: bool,
7981
/// List of features to activate.
8082
pub features: CargoFeatures,
8183
/// rustc target

crates/rust-analyzer/src/config.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ config_data! {
7171
/// How many worker threads to handle priming caches. The default `0` means to pick automatically.
7272
cachePriming_numThreads: ParallelCachePrimingNumThreads = "0",
7373

74+
/// Pass `--all-targets` to cargo invocation. Overridden by `#rust-analyzer.check.allTargets#`
75+
/// when the latter is set.
76+
cargo_allTargets: bool = "true",
7477
/// Automatically refresh project info via `cargo metadata` on
7578
/// `Cargo.toml` or `.cargo/config.toml` changes.
7679
cargo_autoreload: bool = "true",
@@ -163,8 +166,8 @@ config_data! {
163166
/// Run the check command for diagnostics on save.
164167
checkOnSave | checkOnSave_enable: bool = "true",
165168

166-
/// Check all targets and tests (`--all-targets`).
167-
check_allTargets | checkOnSave_allTargets: bool = "true",
169+
/// Check all targets and tests (`--all-targets`). Overrides `#rust-analyzer.cargo.allTargets#`.
170+
check_allTargets | checkOnSave_allTargets: Option<bool> = "null",
168171
/// Cargo command to use for `cargo check`.
169172
check_command | checkOnSave_command: String = "\"check\"",
170173
/// Extra arguments for `cargo check`.
@@ -1273,6 +1276,7 @@ impl Config {
12731276
let sysroot_query_metadata = self.data.cargo_sysrootQueryMetadata;
12741277

12751278
CargoConfig {
1279+
all_targets: self.data.cargo_allTargets,
12761280
features: match &self.data.cargo_features {
12771281
CargoFeaturesDef::All => CargoFeatures::All,
12781282
CargoFeaturesDef::Selected(features) => CargoFeatures::Selected {
@@ -1383,7 +1387,7 @@ impl Config {
13831387
targets => Some(targets.into()),
13841388
})
13851389
.unwrap_or_else(|| self.data.cargo_target.clone().into_iter().collect()),
1386-
all_targets: self.data.check_allTargets,
1390+
all_targets: self.data.check_allTargets.unwrap_or(self.data.cargo_allTargets),
13871391
no_default_features: self
13881392
.data
13891393
.check_noDefaultFeatures

docs/user/generated_config.adoc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ Warm up caches on project load.
1919
--
2020
How many worker threads to handle priming caches. The default `0` means to pick automatically.
2121
--
22+
[[rust-analyzer.cargo.allTargets]]rust-analyzer.cargo.allTargets (default: `true`)::
23+
+
24+
--
25+
Pass `--all-targets` to cargo invocation. Overridden by `#rust-analyzer.check.allTargets#`
26+
when the latter is set.
27+
--
2228
[[rust-analyzer.cargo.autoreload]]rust-analyzer.cargo.autoreload (default: `true`)::
2329
+
2430
--
@@ -164,10 +170,10 @@ Unsets the implicit `#[cfg(test)]` for the specified crates.
164170
--
165171
Run the check command for diagnostics on save.
166172
--
167-
[[rust-analyzer.check.allTargets]]rust-analyzer.check.allTargets (default: `true`)::
173+
[[rust-analyzer.check.allTargets]]rust-analyzer.check.allTargets (default: `null`)::
168174
+
169175
--
170-
Check all targets and tests (`--all-targets`).
176+
Check all targets and tests (`--all-targets`). Overrides `#rust-analyzer.cargo.allTargets#`.
171177
--
172178
[[rust-analyzer.check.command]]rust-analyzer.check.command (default: `"check"`)::
173179
+

editors/code/package.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,11 @@
546546
"minimum": 0,
547547
"maximum": 255
548548
},
549+
"rust-analyzer.cargo.allTargets": {
550+
"markdownDescription": "Pass `--all-targets` to cargo invocation. Overridden by `#rust-analyzer.check.allTargets#`\nwhen the latter is set.",
551+
"default": true,
552+
"type": "boolean"
553+
},
549554
"rust-analyzer.cargo.autoreload": {
550555
"markdownDescription": "Automatically refresh project info via `cargo metadata` on\n`Cargo.toml` or `.cargo/config.toml` changes.",
551556
"default": true,
@@ -707,9 +712,12 @@
707712
"type": "boolean"
708713
},
709714
"rust-analyzer.check.allTargets": {
710-
"markdownDescription": "Check all targets and tests (`--all-targets`).",
711-
"default": true,
712-
"type": "boolean"
715+
"markdownDescription": "Check all targets and tests (`--all-targets`). Overrides `#rust-analyzer.cargo.allTargets#`.",
716+
"default": null,
717+
"type": [
718+
"null",
719+
"boolean"
720+
]
713721
},
714722
"rust-analyzer.check.command": {
715723
"markdownDescription": "Cargo command to use for `cargo check`.",

0 commit comments

Comments
 (0)