diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/dispatch.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/dispatch.rs index ff50f7533a64..4683877db69b 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/dispatch.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/dispatch.rs @@ -118,7 +118,7 @@ impl RequestDispatcher<'_> { } return self; } - self.on_with_thread_intent::( + self.on_with_thread_intent::( ThreadIntent::Worker, f, Self::content_modified_error, @@ -147,7 +147,7 @@ impl RequestDispatcher<'_> { } return self; } - self.on_with_thread_intent::(ThreadIntent::Worker, f, on_cancelled) + self.on_with_thread_intent::(ThreadIntent::Worker, f, on_cancelled) } /// Dispatches a non-latency-sensitive request onto the thread pool. When the VFS is marked not @@ -166,7 +166,7 @@ impl RequestDispatcher<'_> { } return self; } - self.on_with_thread_intent::( + self.on_with_thread_intent::( ThreadIntent::Worker, f, Self::content_modified_error, @@ -193,7 +193,7 @@ impl RequestDispatcher<'_> { } return self; } - self.on_with_thread_intent::( + self.on_with_thread_intent::( ThreadIntent::LatencySensitive, f, Self::content_modified_error, @@ -212,7 +212,7 @@ impl RequestDispatcher<'_> { R::Params: DeserializeOwned + panic::UnwindSafe + Send + fmt::Debug, R::Result: Serialize, { - self.on_with_thread_intent::( + self.on_with_thread_intent::( ThreadIntent::LatencySensitive, f, Self::content_modified_error, @@ -231,7 +231,7 @@ impl RequestDispatcher<'_> { } } - fn on_with_thread_intent( + fn on_with_thread_intent( &mut self, intent: ThreadIntent, f: fn(GlobalStateSnapshot, R::Params) -> anyhow::Result, @@ -251,10 +251,10 @@ impl RequestDispatcher<'_> { tracing::debug!(?params); let world = self.global_state.snapshot(); - if MAIN_POOL { - &mut self.global_state.task_pool.handle - } else { + if RUSTFMT { &mut self.global_state.fmt_pool.handle + } else { + &mut self.global_state.task_pool.handle } .spawn(intent, move || { let result = panic::catch_unwind(move || { diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/main_loop.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/main_loop.rs index d6dc8b521fd6..de0ee639ca55 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/main_loop.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/main_loop.rs @@ -253,6 +253,11 @@ impl GlobalState { &self, inbox: &Receiver, ) -> Result, crossbeam_channel::RecvError> { + // Make sure we reply to formatting requests ASAP so the editor doesn't block + if let Ok(task) = self.fmt_pool.receiver.try_recv() { + return Ok(Some(Event::Task(task))); + } + select! { recv(inbox) -> msg => return Ok(msg.ok().map(Event::Lsp)),