Skip to content

Commit f1de7d7

Browse files
committed
Auto merge of rust-lang#16011 - ClSlaid:feat/settings/proc-macro/rebuild-on-save, r=Veykril
feat: add proc-macro rebuild on save option Related: rust-lang#15033 I need some advice on how to test it.
2 parents e461efb + c99089c commit f1de7d7

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

Diff for: crates/rust-analyzer/src/config.rs

+7
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ config_data! {
105105
/// ```
106106
/// .
107107
cargo_buildScripts_overrideCommand: Option<Vec<String>> = "null",
108+
/// Rerun proc-macros building/build-scripts running when proc-macro
109+
/// or build-script sources change and are saved.
110+
cargo_buildScripts_rebuildOnSave: bool = "false",
108111
/// Use `RUSTC_WRAPPER=rust-analyzer` when running build scripts to
109112
/// avoid checking unnecessary things.
110113
cargo_buildScripts_useRustcWrapper: bool = "true",
@@ -1369,6 +1372,10 @@ impl Config {
13691372
self.data.checkOnSave
13701373
}
13711374

1375+
pub fn script_rebuild_on_save(&self) -> bool {
1376+
self.data.cargo_buildScripts_rebuildOnSave
1377+
}
1378+
13721379
pub fn runnables(&self) -> RunnablesConfig {
13731380
RunnablesConfig {
13741381
override_cargo: self.data.runnables_command.clone(),

Diff for: crates/rust-analyzer/src/handlers/notification.rs

+7
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("ScriptRebuildOnSave".to_owned(), ());
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() {

Diff for: docs/user/generated_config.adoc

+6
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
--

Diff for: editors/code/package.json

+5
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)