Skip to content

Commit 32b0ab1

Browse files
committed
feat: allow selecting which packages to check for buildscripts
1 parent 24cf957 commit 32b0ab1

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

crates/project_model/src/build_scripts.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,16 @@ impl WorkspaceBuildScripts {
5858
cmd.env("RA_RUSTC_WRAPPER", "1");
5959
}
6060
cmd.current_dir(workspace.workspace_root());
61-
cmd.args(&["check", "--quiet", "--workspace", "--message-format=json"]);
61+
cmd.args(&["check", "--quiet", "--message-format=json"]);
62+
63+
if config.build_script_packages.is_empty() {
64+
cmd.arg("--workspace");
65+
} else {
66+
for pkg in &config.build_script_packages {
67+
cmd.arg("-p");
68+
cmd.arg(pkg);
69+
}
70+
}
6271

6372
// --all-targets includes tests, benches and examples in addition to the
6473
// default lib and bins. This is an independent concept from the --targets

crates/project_model/src/cargo_workspace.rs

+2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ pub struct CargoConfig {
9696
pub unset_test_crates: UnsetTestCrates,
9797

9898
pub wrap_rustc_in_build_scripts: bool,
99+
100+
pub build_script_packages: Vec<String>,
99101
}
100102

101103
impl CargoConfig {

crates/rust-analyzer/src/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ config_data! {
8282
/// Use `RUSTC_WRAPPER=rust-analyzer` when running build scripts to
8383
/// avoid compiling unnecessary things.
8484
cargo_useRustcWrapperForBuildScripts: bool = "true",
85+
/// List of packages to checked when running build scripts. It is
86+
/// empty by default, which checks all packages in the workspace.
87+
cargo_buildScriptPackagesToCheck: Vec<String> = "[]",
8588
/// Do not activate the `default` feature.
8689
cargo_noDefaultFeatures: bool = "false",
8790
/// Compilation target (target triple).
@@ -803,6 +806,7 @@ impl Config {
803806
rustc_source,
804807
unset_test_crates: UnsetTestCrates::Only(self.data.cargo_unsetTest.clone()),
805808
wrap_rustc_in_build_scripts: self.data.cargo_useRustcWrapperForBuildScripts,
809+
build_script_packages: self.data.cargo_buildScriptPackagesToCheck.clone(),
806810
}
807811
}
808812

docs/user/generated_config.adoc

+6
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ Run build scripts (`build.rs`) for more precise code analysis.
7070
Use `RUSTC_WRAPPER=rust-analyzer` when running build scripts to
7171
avoid compiling unnecessary things.
7272
--
73+
[[rust-analyzer.cargo.buildScriptPackagesToCheck]]rust-analyzer.cargo.buildScriptPackagesToCheck (default: `[]`)::
74+
+
75+
--
76+
List of packages to checked when running build scripts. It is
77+
empty by default, which checks all packages in the workspace.
78+
--
7379
[[rust-analyzer.cargo.noDefaultFeatures]]rust-analyzer.cargo.noDefaultFeatures (default: `false`)::
7480
+
7581
--

editors/code/package.json

+8
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,14 @@
481481
"default": true,
482482
"type": "boolean"
483483
},
484+
"rust-analyzer.cargo.buildScriptPackagesToCheck": {
485+
"markdownDescription": "List of packages to checked when running build scripts. It is\nempty by default, which checks all packages in the workspace.",
486+
"default": [],
487+
"type": "array",
488+
"items": {
489+
"type": "string"
490+
}
491+
},
484492
"rust-analyzer.cargo.noDefaultFeatures": {
485493
"markdownDescription": "Do not activate the `default` feature.",
486494
"default": false,

0 commit comments

Comments
 (0)