diff --git a/crates/project-model/src/build_scripts.rs b/crates/project-model/src/build_scripts.rs index d40eb26063..e6379bf902 100644 --- a/crates/project-model/src/build_scripts.rs +++ b/crates/project-model/src/build_scripts.rs @@ -86,7 +86,9 @@ impl WorkspaceBuildScripts { // --all-targets includes tests, benches and examples in addition to the // default lib and bins. This is an independent concept from the --target // flag below. - cmd.arg("--all-targets"); + if config.all_targets { + cmd.arg("--all-targets"); + } if let Some(target) = &config.target { cmd.args(["--target", target]); diff --git a/crates/project-model/src/cargo_workspace.rs b/crates/project-model/src/cargo_workspace.rs index 51c1b094f7..82fee7112f 100644 --- a/crates/project-model/src/cargo_workspace.rs +++ b/crates/project-model/src/cargo_workspace.rs @@ -76,6 +76,8 @@ impl Default for CargoFeatures { #[derive(Default, Clone, Debug, PartialEq, Eq)] pub struct CargoConfig { + /// Whether to pass `--all-targets` to cargo invocations. + pub all_targets: bool, /// List of features to activate. pub features: CargoFeatures, /// rustc target diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 7475a8e6e6..205388aeef 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -71,6 +71,9 @@ config_data! { /// How many worker threads to handle priming caches. The default `0` means to pick automatically. cachePriming_numThreads: ParallelCachePrimingNumThreads = "0", + /// Pass `--all-targets` to cargo invocation. Overridden by `#rust-analyzer.check.allTargets#` + /// when the latter is set. + cargo_allTargets: bool = "true", /// Automatically refresh project info via `cargo metadata` on /// `Cargo.toml` or `.cargo/config.toml` changes. cargo_autoreload: bool = "true", @@ -163,8 +166,8 @@ config_data! { /// Run the check command for diagnostics on save. checkOnSave | checkOnSave_enable: bool = "true", - /// Check all targets and tests (`--all-targets`). - check_allTargets | checkOnSave_allTargets: bool = "true", + /// Check all targets and tests (`--all-targets`). Overrides `#rust-analyzer.cargo.allTargets#`. + check_allTargets | checkOnSave_allTargets: Option = "null", /// Cargo command to use for `cargo check`. check_command | checkOnSave_command: String = "\"check\"", /// Extra arguments for `cargo check`. @@ -1284,6 +1287,7 @@ impl Config { let sysroot_query_metadata = self.data.cargo_sysrootQueryMetadata; CargoConfig { + all_targets: self.data.cargo_allTargets, features: match &self.data.cargo_features { CargoFeaturesDef::All => CargoFeatures::All, CargoFeaturesDef::Selected(features) => CargoFeatures::Selected { @@ -1394,7 +1398,7 @@ impl Config { targets => Some(targets.into()), }) .unwrap_or_else(|| self.data.cargo_target.clone().into_iter().collect()), - all_targets: self.data.check_allTargets, + all_targets: self.data.check_allTargets.unwrap_or(self.data.cargo_allTargets), no_default_features: self .data .check_noDefaultFeatures diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc index c4024f6d28..5caefc6422 100644 --- a/docs/user/generated_config.adoc +++ b/docs/user/generated_config.adoc @@ -19,6 +19,12 @@ Warm up caches on project load. -- How many worker threads to handle priming caches. The default `0` means to pick automatically. -- +[[rust-analyzer.cargo.allTargets]]rust-analyzer.cargo.allTargets (default: `true`):: ++ +-- +Pass `--all-targets` to cargo invocation. Overridden by `#rust-analyzer.check.allTargets#` +when the latter is set. +-- [[rust-analyzer.cargo.autoreload]]rust-analyzer.cargo.autoreload (default: `true`):: + -- @@ -164,10 +170,10 @@ Unsets the implicit `#[cfg(test)]` for the specified crates. -- Run the check command for diagnostics on save. -- -[[rust-analyzer.check.allTargets]]rust-analyzer.check.allTargets (default: `true`):: +[[rust-analyzer.check.allTargets]]rust-analyzer.check.allTargets (default: `null`):: + -- -Check all targets and tests (`--all-targets`). +Check all targets and tests (`--all-targets`). Overrides `#rust-analyzer.cargo.allTargets#`. -- [[rust-analyzer.check.command]]rust-analyzer.check.command (default: `"check"`):: + diff --git a/editors/code/package.json b/editors/code/package.json index c3ea1ceeb6..0bfe0cc4e4 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -546,6 +546,11 @@ "minimum": 0, "maximum": 255 }, + "rust-analyzer.cargo.allTargets": { + "markdownDescription": "Pass `--all-targets` to cargo invocation. Overridden by `#rust-analyzer.check.allTargets#`\nwhen the latter is set.", + "default": true, + "type": "boolean" + }, "rust-analyzer.cargo.autoreload": { "markdownDescription": "Automatically refresh project info via `cargo metadata` on\n`Cargo.toml` or `.cargo/config.toml` changes.", "default": true, @@ -707,9 +712,12 @@ "type": "boolean" }, "rust-analyzer.check.allTargets": { - "markdownDescription": "Check all targets and tests (`--all-targets`).", - "default": true, - "type": "boolean" + "markdownDescription": "Check all targets and tests (`--all-targets`). Overrides `#rust-analyzer.cargo.allTargets#`.", + "default": null, + "type": [ + "null", + "boolean" + ] }, "rust-analyzer.check.command": { "markdownDescription": "Cargo command to use for `cargo check`.",