Skip to content

Commit f087ebe

Browse files
committed
Auto merge of #13338 - Veykril:flycheck, r=Veykril
Prioritize restart messages in flycheck cc #12936 (comment)
2 parents 5c28ad1 + 5916803 commit f087ebe

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

crates/flycheck/src/lib.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -169,21 +169,30 @@ impl FlycheckActor {
169169
}
170170
fn next_event(&self, inbox: &Receiver<Restart>) -> Option<Event> {
171171
let check_chan = self.cargo_handle.as_ref().map(|cargo| &cargo.receiver);
172+
if let Ok(msg) = inbox.try_recv() {
173+
// give restarts a preference so check outputs don't block a restart or stop
174+
return Some(Event::Restart(msg));
175+
}
172176
select! {
173177
recv(inbox) -> msg => msg.ok().map(Event::Restart),
174178
recv(check_chan.unwrap_or(&never())) -> msg => Some(Event::CheckEvent(msg.ok())),
175179
}
176180
}
177181
fn run(mut self, inbox: Receiver<Restart>) {
178-
while let Some(event) = self.next_event(&inbox) {
182+
'event: while let Some(event) = self.next_event(&inbox) {
179183
match event {
180184
Event::Restart(Restart::No) => {
181185
self.cancel_check_process();
182186
}
183187
Event::Restart(Restart::Yes) => {
184188
// Cancel the previously spawned process
185189
self.cancel_check_process();
186-
while let Ok(_) = inbox.recv_timeout(Duration::from_millis(50)) {}
190+
while let Ok(restart) = inbox.recv_timeout(Duration::from_millis(50)) {
191+
// restart chained with a stop, so just cancel
192+
if let Restart::No = restart {
193+
continue 'event;
194+
}
195+
}
187196

188197
let command = self.check_command();
189198
tracing::debug!(?command, "will restart flycheck");

0 commit comments

Comments
 (0)