Skip to content

Commit a5a71c7

Browse files
committed
Auto merge of rust-lang#15067 - Veykril:loop-turn-msgh, r=Veykril
internal: Add more context to overly long loop turn message
2 parents 4143890 + bd762e6 commit a5a71c7

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

crates/rust-analyzer/src/dispatch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ pub(crate) struct NotificationDispatcher<'a> {
307307
}
308308

309309
impl<'a> NotificationDispatcher<'a> {
310-
pub(crate) fn on<N>(
310+
pub(crate) fn on_sync_mut<N>(
311311
&mut self,
312312
f: fn(&mut GlobalState, N::Params) -> Result<()>,
313313
) -> Result<&mut Self>

crates/rust-analyzer/src/main_loop.rs

+28-16
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use flycheck::FlycheckHandle;
1111
use ide_db::base_db::{SourceDatabaseExt, VfsPath};
1212
use lsp_server::{Connection, Notification, Request};
1313
use lsp_types::notification::Notification as _;
14+
use stdx::thread::ThreadIntent;
1415
use triomphe::Arc;
1516
use vfs::FileId;
1617

@@ -282,6 +283,7 @@ impl GlobalState {
282283
}
283284
}
284285
}
286+
let event_handling_duration = loop_start.elapsed();
285287

286288
let state_changed = self.process_changes();
287289
let memdocs_added_or_removed = self.mem_docs.take_changes();
@@ -392,9 +394,9 @@ impl GlobalState {
392394

393395
let loop_duration = loop_start.elapsed();
394396
if loop_duration > Duration::from_millis(100) && was_quiescent {
395-
tracing::warn!("overly long loop turn took {loop_duration:?}: {event_dbg_msg}");
397+
tracing::warn!("overly long loop turn took {loop_duration:?} (event handling took {event_handling_duration:?}): {event_dbg_msg}");
396398
self.poke_rust_analyzer_developer(format!(
397-
"overly long loop turn took {loop_duration:?}: {event_dbg_msg}"
399+
"overly long loop turn took {loop_duration:?} (event handling took {event_handling_duration:?}): {event_dbg_msg}"
398400
));
399401
}
400402
Ok(())
@@ -404,7 +406,7 @@ impl GlobalState {
404406
tracing::debug!(%cause, "will prime caches");
405407
let num_worker_threads = self.config.prime_caches_num_threads();
406408

407-
self.task_pool.handle.spawn_with_sender(stdx::thread::ThreadIntent::Worker, {
409+
self.task_pool.handle.spawn_with_sender(ThreadIntent::Worker, {
408410
let analysis = self.snapshot().analysis;
409411
move |sender| {
410412
sender.send(Task::PrimeCaches(PrimeCachesProgress::Begin)).unwrap();
@@ -761,18 +763,28 @@ impl GlobalState {
761763
use lsp_types::notification as notifs;
762764

763765
NotificationDispatcher { not: Some(not), global_state: self }
764-
.on::<notifs::Cancel>(handlers::handle_cancel)?
765-
.on::<notifs::WorkDoneProgressCancel>(handlers::handle_work_done_progress_cancel)?
766-
.on::<notifs::DidOpenTextDocument>(handlers::handle_did_open_text_document)?
767-
.on::<notifs::DidChangeTextDocument>(handlers::handle_did_change_text_document)?
768-
.on::<notifs::DidCloseTextDocument>(handlers::handle_did_close_text_document)?
769-
.on::<notifs::DidSaveTextDocument>(handlers::handle_did_save_text_document)?
770-
.on::<notifs::DidChangeConfiguration>(handlers::handle_did_change_configuration)?
771-
.on::<notifs::DidChangeWorkspaceFolders>(handlers::handle_did_change_workspace_folders)?
772-
.on::<notifs::DidChangeWatchedFiles>(handlers::handle_did_change_watched_files)?
773-
.on::<lsp_ext::CancelFlycheck>(handlers::handle_cancel_flycheck)?
774-
.on::<lsp_ext::ClearFlycheck>(handlers::handle_clear_flycheck)?
775-
.on::<lsp_ext::RunFlycheck>(handlers::handle_run_flycheck)?
766+
.on_sync_mut::<notifs::Cancel>(handlers::handle_cancel)?
767+
.on_sync_mut::<notifs::WorkDoneProgressCancel>(
768+
handlers::handle_work_done_progress_cancel,
769+
)?
770+
.on_sync_mut::<notifs::DidOpenTextDocument>(handlers::handle_did_open_text_document)?
771+
.on_sync_mut::<notifs::DidChangeTextDocument>(
772+
handlers::handle_did_change_text_document,
773+
)?
774+
.on_sync_mut::<notifs::DidCloseTextDocument>(handlers::handle_did_close_text_document)?
775+
.on_sync_mut::<notifs::DidSaveTextDocument>(handlers::handle_did_save_text_document)?
776+
.on_sync_mut::<notifs::DidChangeConfiguration>(
777+
handlers::handle_did_change_configuration,
778+
)?
779+
.on_sync_mut::<notifs::DidChangeWorkspaceFolders>(
780+
handlers::handle_did_change_workspace_folders,
781+
)?
782+
.on_sync_mut::<notifs::DidChangeWatchedFiles>(
783+
handlers::handle_did_change_watched_files,
784+
)?
785+
.on_sync_mut::<lsp_ext::CancelFlycheck>(handlers::handle_cancel_flycheck)?
786+
.on_sync_mut::<lsp_ext::ClearFlycheck>(handlers::handle_clear_flycheck)?
787+
.on_sync_mut::<lsp_ext::RunFlycheck>(handlers::handle_run_flycheck)?
776788
.finish();
777789
Ok(())
778790
}
@@ -800,7 +812,7 @@ impl GlobalState {
800812

801813
// Diagnostics are triggered by the user typing
802814
// so we run them on a latency sensitive thread.
803-
self.task_pool.handle.spawn(stdx::thread::ThreadIntent::LatencySensitive, move || {
815+
self.task_pool.handle.spawn(ThreadIntent::LatencySensitive, move || {
804816
let _p = profile::span("publish_diagnostics");
805817
let _ctx = stdx::panic_context::enter("publish_diagnostics".to_owned());
806818
let diagnostics = subscriptions

0 commit comments

Comments
 (0)