diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs index 8e947b5540..bef943464a 100644 --- a/crates/rust-analyzer/src/global_state.rs +++ b/crates/rust-analyzer/src/global_state.rs @@ -8,7 +8,7 @@ use std::{sync::Arc, time::Instant}; use crossbeam_channel::{unbounded, Receiver, Sender}; use flycheck::FlycheckHandle; use ide::{Analysis, AnalysisHost, Cancellable, Change, FileId}; -use ide_db::base_db::CrateId; +use ide_db::base_db::{CrateId, FileLoader, SourceDatabase}; use lsp_types::{SemanticTokens, Url}; use parking_lot::{Mutex, RwLock}; use proc_macro_api::ProcMacroServer; @@ -58,6 +58,7 @@ pub(crate) struct GlobalState { pub(crate) mem_docs: MemDocs, pub(crate) semantic_tokens_cache: Arc>>, pub(crate) shutdown_requested: bool, + pub(crate) proc_macro_changed: bool, pub(crate) last_reported_status: Option, pub(crate) source_root_config: SourceRootConfig, pub(crate) proc_macro_client: Option, @@ -147,6 +148,7 @@ impl GlobalState { mem_docs: MemDocs::default(), semantic_tokens_cache: Arc::new(Default::default()), shutdown_requested: false, + proc_macro_changed: false, last_reported_status: None, source_root_config: SourceRootConfig::default(), proc_macro_client: None, @@ -187,6 +189,15 @@ impl GlobalState { } for file in changed_files { + if !file.is_created_or_deleted() { + let crates = self.analysis_host.raw_database().relevant_crates(file.file_id); + let crate_graph = self.analysis_host.raw_database().crate_graph(); + + if crates.iter().any(|&krate| !crate_graph[krate].proc_macro.is_empty()) { + self.proc_macro_changed = true; + } + } + if let Some(path) = vfs.file_path(file.file_id).as_path() { let path = path.to_path_buf(); if reload::should_refresh_for_change(&path, file.change_kind) { diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 9f08ad5ebf..4a1060596b 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -561,7 +561,7 @@ impl GlobalState { s.shutdown_requested = true; Ok(()) })? - .on_sync_mut::(|s, p| handlers::handle_memory_usage(s, p))? + .on_sync_mut::(handlers::handle_memory_usage)? .on_sync::(handlers::handle_join_lines)? .on_sync::(handlers::handle_on_enter)? .on_sync::(handlers::handle_selection_range)? diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index 6a6df9c1dd..7ba5697176 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs @@ -66,6 +66,11 @@ impl GlobalState { message: None, }; + if self.proc_macro_changed { + status.health = lsp_ext::Health::Warning; + status.message = + Some("Reload required due to source changes of a procedural macro.".into()) + } if let Some(error) = self.fetch_build_data_error() { status.health = lsp_ext::Health::Warning; status.message = Some(error)