Auto merge of #16011 - ClSlaid:feat/settings/proc-macro/rebuild-on-save, r=Veykril

feat: add proc-macro rebuild on save option

Related: #15033

I need some advice on how to test it.
This commit is contained in:
bors 2024-01-02 09:46:21 +00:00
commit f1de7d7273
4 changed files with 25 additions and 0 deletions

View file

@ -105,6 +105,9 @@ config_data! {
/// ``` /// ```
/// . /// .
cargo_buildScripts_overrideCommand: Option<Vec<String>> = "null", cargo_buildScripts_overrideCommand: Option<Vec<String>> = "null",
/// 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 /// Use `RUSTC_WRAPPER=rust-analyzer` when running build scripts to
/// avoid checking unnecessary things. /// avoid checking unnecessary things.
cargo_buildScripts_useRustcWrapper: bool = "true", cargo_buildScripts_useRustcWrapper: bool = "true",
@ -1369,6 +1372,10 @@ impl Config {
self.data.checkOnSave self.data.checkOnSave
} }
pub fn script_rebuild_on_save(&self) -> bool {
self.data.cargo_buildScripts_rebuildOnSave
}
pub fn runnables(&self) -> RunnablesConfig { pub fn runnables(&self) -> RunnablesConfig {
RunnablesConfig { RunnablesConfig {
override_cargo: self.data.runnables_command.clone(), override_cargo: self.data.runnables_command.clone(),

View file

@ -130,6 +130,13 @@ pub(crate) fn handle_did_save_text_document(
state: &mut GlobalState, state: &mut GlobalState,
params: DidSaveTextDocumentParams, params: DidSaveTextDocumentParams,
) -> anyhow::Result<()> { ) -> 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("ScriptRebuildOnSave".to_owned(), ());
}
if let Ok(vfs_path) = from_proto::vfs_path(&params.text_document.uri) { if let Ok(vfs_path) = from_proto::vfs_path(&params.text_document.uri) {
// Re-fetch workspaces if a workspace related file has changed // Re-fetch workspaces if a workspace related file has changed
if let Some(abs_path) = vfs_path.as_path() { 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`):: [[rust-analyzer.cargo.buildScripts.useRustcWrapper]]rust-analyzer.cargo.buildScripts.useRustcWrapper (default: `true`)::
+ +
-- --

View file

@ -586,6 +586,11 @@
"type": "string" "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": { "rust-analyzer.cargo.buildScripts.useRustcWrapper": {
"markdownDescription": "Use `RUSTC_WRAPPER=rust-analyzer` when running build scripts to\navoid checking unnecessary things.", "markdownDescription": "Use `RUSTC_WRAPPER=rust-analyzer` when running build scripts to\navoid checking unnecessary things.",
"default": true, "default": true,