Skip to content

Commit

Permalink
Auto merge of #16924 - poliorcetics:ab/push-kxwqvtypvlsq, r=Veykril
Browse files Browse the repository at this point in the history
feat: Add `rust-analyzer.cargo.allTargets` to configure passing `--all-targets` to cargo invocations

Closes #16859

## Unresolved question:

Should this be a setting for build scripts only ? All the other `--all-targets` I found where already covered by `checkOnSave.allTargets`
  • Loading branch information
bors committed Apr 1, 2024
2 parents f3f14d4 + 174af88 commit 2678660
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
4 changes: 3 additions & 1 deletion crates/project-model/src/build_scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
2 changes: 2 additions & 0 deletions crates/project-model/src/cargo_workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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<bool> = "null",
/// Cargo command to use for `cargo check`.
check_command | checkOnSave_command: String = "\"check\"",
/// Extra arguments for `cargo check`.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions docs/user/generated_config.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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`)::
+
--
Expand Down Expand Up @@ -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"`)::
+
Expand Down
14 changes: 11 additions & 3 deletions editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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`.",
Expand Down

0 comments on commit 2678660

Please sign in to comment.