Skip to content

Commit ad27b6e

Browse files
committed
patch: only rerun build scripts when saved.
Signed-off-by: 蔡略 <[email protected]>
1 parent b21d68c commit ad27b6e

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ config_data! {
105105
/// ```
106106
/// .
107107
cargo_buildScripts_overrideCommand: Option<Vec<String>> = "null",
108-
/// rerun proc-macros building/build-scripts running when proc-macro
108+
/// Rerun proc-macros building/build-scripts running when proc-macro
109109
/// or build-script sources change and are saved.
110110
cargo_buildScripts_rebuildOnSave: bool = "false",
111111
/// Use `RUSTC_WRAPPER=rust-analyzer` when running build scripts to

crates/rust-analyzer/src/global_state.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,6 @@ impl GlobalState {
351351

352352
crates.iter().any(|&krate| crate_graph[krate].is_proc_macro)
353353
});
354-
if self.proc_macro_changed && self.config.script_rebuild_on_save() {
355-
self.fetch_build_data_queue
356-
.request_op(format!("proc-macro or build script source changed"), ())
357-
}
358354
}
359355

360356
true

crates/rust-analyzer/src/handlers/notification.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ pub(crate) fn handle_did_save_text_document(
130130
state: &mut GlobalState,
131131
params: DidSaveTextDocumentParams,
132132
) -> anyhow::Result<()> {
133+
if state.config.script_rebuild_on_save() && state.proc_macro_changed {
134+
// reset the flag
135+
state.proc_macro_changed = false;
136+
// rebuild the proc macros
137+
state.fetch_build_data_queue.request_op(format!("ScriptRebuildOnSave"), ());
138+
}
139+
133140
if let Ok(vfs_path) = from_proto::vfs_path(&params.text_document.uri) {
134141
// Re-fetch workspaces if a workspace related file has changed
135142
if let Some(abs_path) = vfs_path.as_path() {

docs/user/generated_config.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ cargo check --quiet --workspace --message-format=json --all-targets
7171
```
7272
.
7373
--
74+
[[rust-analyzer.cargo.buildScripts.rebuildOnSave]]rust-analyzer.cargo.buildScripts.rebuildOnSave (default: `false`)::
75+
+
76+
--
77+
Rerun proc-macros building/build-scripts running when proc-macro
78+
or build-script sources change and are saved.
79+
--
7480
[[rust-analyzer.cargo.buildScripts.useRustcWrapper]]rust-analyzer.cargo.buildScripts.useRustcWrapper (default: `true`)::
7581
+
7682
--

editors/code/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,11 @@
586586
"type": "string"
587587
}
588588
},
589+
"rust-analyzer.cargo.buildScripts.rebuildOnSave": {
590+
"markdownDescription": "Rerun proc-macros building/build-scripts running when proc-macro\nor build-script sources change and are saved.",
591+
"default": false,
592+
"type": "boolean"
593+
},
589594
"rust-analyzer.cargo.buildScripts.useRustcWrapper": {
590595
"markdownDescription": "Use `RUSTC_WRAPPER=rust-analyzer` when running build scripts to\navoid checking unnecessary things.",
591596
"default": true,

0 commit comments

Comments
 (0)