Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/rust-analyzer/src/config.rs2
-rw-r--r--crates/rust-analyzer/src/global_state.rs4
-rw-r--r--crates/rust-analyzer/src/handlers/notification.rs7
-rw-r--r--docs/user/generated_config.adoc6
-rw-r--r--editors/code/package.json5
5 files changed, 19 insertions, 5 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 33ba466236..8700db5d8f 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -105,7 +105,7 @@ config_data! {
/// ```
/// .
cargo_buildScripts_overrideCommand: Option<Vec<String>> = "null",
- /// rerun proc-macros building/build-scripts running when proc-macro
+ /// Rerun proc-macros building/build-scripts running when proc-macro
/// or build-script sources change and are saved.
cargo_buildScripts_rebuildOnSave: bool = "false",
/// Use `RUSTC_WRAPPER=rust-analyzer` when running build scripts to
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs
index 60dc5dc522..c09f57252c 100644
--- a/crates/rust-analyzer/src/global_state.rs
+++ b/crates/rust-analyzer/src/global_state.rs
@@ -351,10 +351,6 @@ impl GlobalState {
crates.iter().any(|&krate| crate_graph[krate].is_proc_macro)
});
- if self.proc_macro_changed && self.config.script_rebuild_on_save() {
- self.fetch_build_data_queue
- .request_op(format!("proc-macro or build script source changed"), ())
- }
}
true
diff --git a/crates/rust-analyzer/src/handlers/notification.rs b/crates/rust-analyzer/src/handlers/notification.rs
index f9070d2735..60a3edb9dd 100644
--- a/crates/rust-analyzer/src/handlers/notification.rs
+++ b/crates/rust-analyzer/src/handlers/notification.rs
@@ -130,6 +130,13 @@ pub(crate) fn handle_did_save_text_document(
state: &mut GlobalState,
params: DidSaveTextDocumentParams,
) -> anyhow::Result<()> {
+ if state.config.script_rebuild_on_save() && state.proc_macro_changed {
+ // reset the flag
+ state.proc_macro_changed = false;
+ // rebuild the proc macros
+ state.fetch_build_data_queue.request_op(format!("ScriptRebuildOnSave"), ());
+ }
+
if let Ok(vfs_path) = from_proto::vfs_path(&params.text_document.uri) {
// Re-fetch workspaces if a workspace related file has changed
if let Some(abs_path) = vfs_path.as_path() {
diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc
index 8a2d080844..93663c5206 100644
--- a/docs/user/generated_config.adoc
+++ b/docs/user/generated_config.adoc
@@ -71,6 +71,12 @@ cargo check --quiet --workspace --message-format=json --all-targets
```
.
--
+[[rust-analyzer.cargo.buildScripts.rebuildOnSave]]rust-analyzer.cargo.buildScripts.rebuildOnSave (default: `false`)::
++
+--
+Rerun proc-macros building/build-scripts running when proc-macro
+or build-script sources change and are saved.
+--
[[rust-analyzer.cargo.buildScripts.useRustcWrapper]]rust-analyzer.cargo.buildScripts.useRustcWrapper (default: `true`)::
+
--
diff --git a/editors/code/package.json b/editors/code/package.json
index cfaf421327..2f5eeba41a 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -586,6 +586,11 @@
"type": "string"
}
},
+ "rust-analyzer.cargo.buildScripts.rebuildOnSave": {
+ "markdownDescription": "Rerun proc-macros building/build-scripts running when proc-macro\nor build-script sources change and are saved.",
+ "default": false,
+ "type": "boolean"
+ },
"rust-analyzer.cargo.buildScripts.useRustcWrapper": {
"markdownDescription": "Use `RUSTC_WRAPPER=rust-analyzer` when running build scripts to\navoid checking unnecessary things.",
"default": true,