patch: only rerun build scripts when saved.

Signed-off-by: 蔡略 <cailue@bupt.edu.cn>
This commit is contained in:
蔡略 2023-12-08 11:31:56 +08:00
parent b21d68cd2a
commit ad27b6e053
5 changed files with 19 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

@ -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() {

View File

@ -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`)::
+
--

View File

@ -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,