Skip to content

Commit

Permalink
Auto merge of rust-lang#13338 - Veykril:flycheck, r=Veykril
Browse files Browse the repository at this point in the history
Prioritize restart messages in flycheck

cc rust-lang/rust-analyzer#12936 (comment)
  • Loading branch information
bors committed Oct 3, 2022
2 parents 5c28ad1 + 5916803 commit f087ebe
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions crates/flycheck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,21 +169,30 @@ impl FlycheckActor {
}
fn next_event(&self, inbox: &Receiver<Restart>) -> Option<Event> {
let check_chan = self.cargo_handle.as_ref().map(|cargo| &cargo.receiver);
if let Ok(msg) = inbox.try_recv() {
// give restarts a preference so check outputs don't block a restart or stop
return Some(Event::Restart(msg));
}
select! {
recv(inbox) -> msg => msg.ok().map(Event::Restart),
recv(check_chan.unwrap_or(&never())) -> msg => Some(Event::CheckEvent(msg.ok())),
}
}
fn run(mut self, inbox: Receiver<Restart>) {
while let Some(event) = self.next_event(&inbox) {
'event: while let Some(event) = self.next_event(&inbox) {
match event {
Event::Restart(Restart::No) => {
self.cancel_check_process();
}
Event::Restart(Restart::Yes) => {
// Cancel the previously spawned process
self.cancel_check_process();
while let Ok(_) = inbox.recv_timeout(Duration::from_millis(50)) {}
while let Ok(restart) = inbox.recv_timeout(Duration::from_millis(50)) {
// restart chained with a stop, so just cancel
if let Restart::No = restart {
continue 'event;
}
}

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

0 comments on commit f087ebe

Please sign in to comment.