Skip to content

Commit 30b6063

Browse files
authored
Merge pull request #19052 from Veykril/push-yqwutllwwyyp
Prioritize formatting thread tasks in main_loop
2 parents d60afec + 26c5708 commit 30b6063

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/dispatch.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl RequestDispatcher<'_> {
118118
}
119119
return self;
120120
}
121-
self.on_with_thread_intent::<true, ALLOW_RETRYING, R>(
121+
self.on_with_thread_intent::<false, ALLOW_RETRYING, R>(
122122
ThreadIntent::Worker,
123123
f,
124124
Self::content_modified_error,
@@ -147,7 +147,7 @@ impl RequestDispatcher<'_> {
147147
}
148148
return self;
149149
}
150-
self.on_with_thread_intent::<true, false, R>(ThreadIntent::Worker, f, on_cancelled)
150+
self.on_with_thread_intent::<false, false, R>(ThreadIntent::Worker, f, on_cancelled)
151151
}
152152

153153
/// Dispatches a non-latency-sensitive request onto the thread pool. When the VFS is marked not
@@ -166,7 +166,7 @@ impl RequestDispatcher<'_> {
166166
}
167167
return self;
168168
}
169-
self.on_with_thread_intent::<true, ALLOW_RETRYING, R>(
169+
self.on_with_thread_intent::<false, ALLOW_RETRYING, R>(
170170
ThreadIntent::Worker,
171171
f,
172172
Self::content_modified_error,
@@ -193,7 +193,7 @@ impl RequestDispatcher<'_> {
193193
}
194194
return self;
195195
}
196-
self.on_with_thread_intent::<true, ALLOW_RETRYING, R>(
196+
self.on_with_thread_intent::<false, ALLOW_RETRYING, R>(
197197
ThreadIntent::LatencySensitive,
198198
f,
199199
Self::content_modified_error,
@@ -212,7 +212,7 @@ impl RequestDispatcher<'_> {
212212
R::Params: DeserializeOwned + panic::UnwindSafe + Send + fmt::Debug,
213213
R::Result: Serialize,
214214
{
215-
self.on_with_thread_intent::<false, false, R>(
215+
self.on_with_thread_intent::<true, false, R>(
216216
ThreadIntent::LatencySensitive,
217217
f,
218218
Self::content_modified_error,
@@ -231,7 +231,7 @@ impl RequestDispatcher<'_> {
231231
}
232232
}
233233

234-
fn on_with_thread_intent<const MAIN_POOL: bool, const ALLOW_RETRYING: bool, R>(
234+
fn on_with_thread_intent<const RUSTFMT: bool, const ALLOW_RETRYING: bool, R>(
235235
&mut self,
236236
intent: ThreadIntent,
237237
f: fn(GlobalStateSnapshot, R::Params) -> anyhow::Result<R::Result>,
@@ -251,10 +251,10 @@ impl RequestDispatcher<'_> {
251251
tracing::debug!(?params);
252252

253253
let world = self.global_state.snapshot();
254-
if MAIN_POOL {
255-
&mut self.global_state.task_pool.handle
256-
} else {
254+
if RUSTFMT {
257255
&mut self.global_state.fmt_pool.handle
256+
} else {
257+
&mut self.global_state.task_pool.handle
258258
}
259259
.spawn(intent, move || {
260260
let result = panic::catch_unwind(move || {

src/tools/rust-analyzer/crates/rust-analyzer/src/main_loop.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,11 @@ impl GlobalState {
253253
&self,
254254
inbox: &Receiver<lsp_server::Message>,
255255
) -> Result<Option<Event>, crossbeam_channel::RecvError> {
256+
// Make sure we reply to formatting requests ASAP so the editor doesn't block
257+
if let Ok(task) = self.fmt_pool.receiver.try_recv() {
258+
return Ok(Some(Event::Task(task)));
259+
}
260+
256261
select! {
257262
recv(inbox) -> msg =>
258263
return Ok(msg.ok().map(Event::Lsp)),

0 commit comments

Comments
 (0)