Merge #10596
10596: internal: Set server status to warning when proc-macro sources change r=Veykril a=Veykril Fixes https://github.com/rust-analyzer/rust-analyzer/issues/10027 ![image](https://user-images.githubusercontent.com/3757771/138102552-208d3edf-a843-49e6-9f48-1e911f54a4ba.png) It feels wrong using the database in this part of the code, but this was the only way to figure out whether a file belongs to a proc-macro that I could think of. Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
53b5b2fdaa
@ -8,7 +8,7 @@
|
||||
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<Mutex<FxHashMap<Url, SemanticTokens>>>,
|
||||
pub(crate) shutdown_requested: bool,
|
||||
pub(crate) proc_macro_changed: bool,
|
||||
pub(crate) last_reported_status: Option<lsp_ext::ServerStatusParams>,
|
||||
pub(crate) source_root_config: SourceRootConfig,
|
||||
pub(crate) proc_macro_client: Option<ProcMacroServer>,
|
||||
@ -147,6 +148,7 @@ pub(crate) fn new(sender: Sender<lsp_server::Message>, config: Config) -> Global
|
||||
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 @@ pub(crate) fn process_changes(&mut self) -> bool {
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -561,7 +561,7 @@ fn on_request(&mut self, request_received: Instant, req: Request) -> Result<()>
|
||||
s.shutdown_requested = true;
|
||||
Ok(())
|
||||
})?
|
||||
.on_sync_mut::<lsp_ext::MemoryUsage>(|s, p| handlers::handle_memory_usage(s, p))?
|
||||
.on_sync_mut::<lsp_ext::MemoryUsage>(handlers::handle_memory_usage)?
|
||||
.on_sync::<lsp_ext::JoinLines>(handlers::handle_join_lines)?
|
||||
.on_sync::<lsp_ext::OnEnter>(handlers::handle_on_enter)?
|
||||
.on_sync::<lsp_types::request::SelectionRangeRequest>(handlers::handle_selection_range)?
|
||||
|
@ -66,6 +66,11 @@ pub(crate) fn current_status(&self) -> lsp_ext::ServerStatusParams {
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user