Skip to content

Commit 578d994

Browse files
committed
Move on-type formatting request handler onto the main thread
1 parent a416248 commit 578d994

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

crates/rust-analyzer/src/main_loop.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,14 +652,20 @@ impl GlobalState {
652652
use crate::handlers::request as handlers;
653653

654654
dispatcher
655+
// Request handlers that must run on the main thread
656+
// because they mutate GlobalState:
655657
.on_sync_mut::<lsp_ext::ReloadWorkspace>(handlers::handle_workspace_reload)
656658
.on_sync_mut::<lsp_ext::RebuildProcMacros>(handlers::handle_proc_macros_rebuild)
657659
.on_sync_mut::<lsp_ext::MemoryUsage>(handlers::handle_memory_usage)
658660
.on_sync_mut::<lsp_ext::ShuffleCrateGraph>(handlers::handle_shuffle_crate_graph)
661+
// Request handlers which are related to the user typing
662+
// are run on the main thread to reduce latency:
659663
.on_sync::<lsp_ext::JoinLines>(handlers::handle_join_lines)
660664
.on_sync::<lsp_ext::OnEnter>(handlers::handle_on_enter)
661665
.on_sync::<lsp_types::request::SelectionRangeRequest>(handlers::handle_selection_range)
662666
.on_sync::<lsp_ext::MatchingBrace>(handlers::handle_matching_brace)
667+
.on_sync::<lsp_ext::OnTypeFormatting>(handlers::handle_on_type_formatting)
668+
// All other request handlers:
663669
.on::<lsp_ext::FetchDependencyList>(handlers::fetch_dependency_list)
664670
.on::<lsp_ext::AnalyzerStatus>(handlers::handle_analyzer_status)
665671
.on::<lsp_ext::SyntaxTree>(handlers::handle_syntax_tree)
@@ -680,7 +686,6 @@ impl GlobalState {
680686
.on::<lsp_ext::OpenCargoToml>(handlers::handle_open_cargo_toml)
681687
.on::<lsp_ext::MoveItem>(handlers::handle_move_item)
682688
.on::<lsp_ext::WorkspaceSymbol>(handlers::handle_workspace_symbol)
683-
.on::<lsp_ext::OnTypeFormatting>(handlers::handle_on_type_formatting)
684689
.on::<lsp_types::request::DocumentSymbolRequest>(handlers::handle_document_symbol)
685690
.on::<lsp_types::request::GotoDefinition>(handlers::handle_goto_definition)
686691
.on::<lsp_types::request::GotoDeclaration>(handlers::handle_goto_declaration)

0 commit comments

Comments
 (0)