From 578d99477ab4e01721372014c1fdaf3479fdf34d Mon Sep 17 00:00:00 2001 From: Luna Razzaghipour Date: Thu, 25 May 2023 00:16:52 +1000 Subject: [PATCH] Move on-type formatting request handler onto the main thread --- crates/rust-analyzer/src/main_loop.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index f06abe0763..7464c47a9f 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -652,14 +652,20 @@ impl GlobalState { use crate::handlers::request as handlers; dispatcher + // Request handlers that must run on the main thread + // because they mutate GlobalState: .on_sync_mut::(handlers::handle_workspace_reload) .on_sync_mut::(handlers::handle_proc_macros_rebuild) .on_sync_mut::(handlers::handle_memory_usage) .on_sync_mut::(handlers::handle_shuffle_crate_graph) + // Request handlers which are related to the user typing + // are run on the main thread to reduce latency: .on_sync::(handlers::handle_join_lines) .on_sync::(handlers::handle_on_enter) .on_sync::(handlers::handle_selection_range) .on_sync::(handlers::handle_matching_brace) + .on_sync::(handlers::handle_on_type_formatting) + // All other request handlers: .on::(handlers::fetch_dependency_list) .on::(handlers::handle_analyzer_status) .on::(handlers::handle_syntax_tree) @@ -680,7 +686,6 @@ impl GlobalState { .on::(handlers::handle_open_cargo_toml) .on::(handlers::handle_move_item) .on::(handlers::handle_workspace_symbol) - .on::(handlers::handle_on_type_formatting) .on::(handlers::handle_document_symbol) .on::(handlers::handle_goto_definition) .on::(handlers::handle_goto_declaration)