From bd762e62df617c0048f6279bc3f04c2b3da6d5de Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 16 Jun 2023 19:31:07 +0200 Subject: [PATCH] internal: Add more context to overly long loop turn message --- crates/rust-analyzer/src/dispatch.rs | 2 +- crates/rust-analyzer/src/main_loop.rs | 44 +++++++++++++++++---------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/crates/rust-analyzer/src/dispatch.rs b/crates/rust-analyzer/src/dispatch.rs index 8a0ad88b654..4e57c6eb65a 100644 --- a/crates/rust-analyzer/src/dispatch.rs +++ b/crates/rust-analyzer/src/dispatch.rs @@ -307,7 +307,7 @@ pub(crate) struct NotificationDispatcher<'a> { } impl<'a> NotificationDispatcher<'a> { - pub(crate) fn on( + pub(crate) fn on_sync_mut( &mut self, f: fn(&mut GlobalState, N::Params) -> Result<()>, ) -> Result<&mut Self> diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index c70f60513b5..02dd94e5fa5 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -11,6 +11,7 @@ use ide_db::base_db::{SourceDatabaseExt, VfsPath}; use lsp_server::{Connection, Notification, Request}; use lsp_types::notification::Notification as _; +use stdx::thread::ThreadIntent; use triomphe::Arc; use vfs::FileId; @@ -282,6 +283,7 @@ fn handle_event(&mut self, event: Event) -> Result<()> { } } } + let event_handling_duration = loop_start.elapsed(); let state_changed = self.process_changes(); let memdocs_added_or_removed = self.mem_docs.take_changes(); @@ -392,9 +394,9 @@ fn handle_event(&mut self, event: Event) -> Result<()> { let loop_duration = loop_start.elapsed(); if loop_duration > Duration::from_millis(100) && was_quiescent { - tracing::warn!("overly long loop turn took {loop_duration:?}: {event_dbg_msg}"); + tracing::warn!("overly long loop turn took {loop_duration:?} (event handling took {event_handling_duration:?}): {event_dbg_msg}"); self.poke_rust_analyzer_developer(format!( - "overly long loop turn took {loop_duration:?}: {event_dbg_msg}" + "overly long loop turn took {loop_duration:?} (event handling took {event_handling_duration:?}): {event_dbg_msg}" )); } Ok(()) @@ -404,7 +406,7 @@ fn prime_caches(&mut self, cause: String) { tracing::debug!(%cause, "will prime caches"); let num_worker_threads = self.config.prime_caches_num_threads(); - self.task_pool.handle.spawn_with_sender(stdx::thread::ThreadIntent::Worker, { + self.task_pool.handle.spawn_with_sender(ThreadIntent::Worker, { let analysis = self.snapshot().analysis; move |sender| { sender.send(Task::PrimeCaches(PrimeCachesProgress::Begin)).unwrap(); @@ -761,18 +763,28 @@ fn on_notification(&mut self, not: Notification) -> Result<()> { use lsp_types::notification as notifs; NotificationDispatcher { not: Some(not), global_state: self } - .on::(handlers::handle_cancel)? - .on::(handlers::handle_work_done_progress_cancel)? - .on::(handlers::handle_did_open_text_document)? - .on::(handlers::handle_did_change_text_document)? - .on::(handlers::handle_did_close_text_document)? - .on::(handlers::handle_did_save_text_document)? - .on::(handlers::handle_did_change_configuration)? - .on::(handlers::handle_did_change_workspace_folders)? - .on::(handlers::handle_did_change_watched_files)? - .on::(handlers::handle_cancel_flycheck)? - .on::(handlers::handle_clear_flycheck)? - .on::(handlers::handle_run_flycheck)? + .on_sync_mut::(handlers::handle_cancel)? + .on_sync_mut::( + handlers::handle_work_done_progress_cancel, + )? + .on_sync_mut::(handlers::handle_did_open_text_document)? + .on_sync_mut::( + handlers::handle_did_change_text_document, + )? + .on_sync_mut::(handlers::handle_did_close_text_document)? + .on_sync_mut::(handlers::handle_did_save_text_document)? + .on_sync_mut::( + handlers::handle_did_change_configuration, + )? + .on_sync_mut::( + handlers::handle_did_change_workspace_folders, + )? + .on_sync_mut::( + handlers::handle_did_change_watched_files, + )? + .on_sync_mut::(handlers::handle_cancel_flycheck)? + .on_sync_mut::(handlers::handle_clear_flycheck)? + .on_sync_mut::(handlers::handle_run_flycheck)? .finish(); Ok(()) } @@ -800,7 +812,7 @@ fn update_diagnostics(&mut self) { // Diagnostics are triggered by the user typing // so we run them on a latency sensitive thread. - self.task_pool.handle.spawn(stdx::thread::ThreadIntent::LatencySensitive, move || { + self.task_pool.handle.spawn(ThreadIntent::LatencySensitive, move || { let _p = profile::span("publish_diagnostics"); let _ctx = stdx::panic_context::enter("publish_diagnostics".to_owned()); let diagnostics = subscriptions