From ad27b6e05372a2d68c4abe3718ca85396a456f9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=94=A1=E7=95=A5?= Date: Fri, 8 Dec 2023 11:31:56 +0800 Subject: [PATCH] patch: only rerun build scripts when saved. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 蔡略 --- crates/rust-analyzer/src/config.rs | 2 +- crates/rust-analyzer/src/global_state.rs | 4 ---- crates/rust-analyzer/src/handlers/notification.rs | 7 +++++++ docs/user/generated_config.adoc | 6 ++++++ editors/code/package.json | 5 +++++ 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 33ba4662369..8700db5d8f2 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> = "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 60dc5dc5221..c09f57252ce 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 f9070d27353..60a3edb9ddd 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(¶ms.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 8a2d0808443..93663c52061 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 cfaf4213277..2f5eeba41ab 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,