summary refs log tree commit diff
path: root/src/tools/rust-analyzer/crates/flycheck
diff options
context:
space:
mode:
authorLaurențiu Nicola <lnicola@dend.ro>2022-10-11 10:37:35 +0300
committerLaurențiu Nicola <lnicola@dend.ro>2022-10-11 10:37:35 +0300
commitc867288d1b05bb7b4e069e3fd6c2d16bdc2bfd4b (patch)
treeb5e5b4572532856e412d15ec05337cc1e337a35e /src/tools/rust-analyzer/crates/flycheck
parent518263d889818d16a09a8260f212f8ff4bf345f1 (diff)
parent61504c8d951c566eb03037dcb300c96f4bd9a8b6 (diff)
downloadrust-c867288d1b05bb7b4e069e3fd6c2d16bdc2bfd4b.tar.gz
rust-c867288d1b05bb7b4e069e3fd6c2d16bdc2bfd4b.zip
:arrow_up: rust-analyzer
Diffstat (limited to 'src/tools/rust-analyzer/crates/flycheck')
-rw-r--r--src/tools/rust-analyzer/crates/flycheck/src/lib.rs13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/tools/rust-analyzer/crates/flycheck/src/lib.rs b/src/tools/rust-analyzer/crates/flycheck/src/lib.rs
index fdc03f4053a..e8c63d410aa 100644
--- a/src/tools/rust-analyzer/crates/flycheck/src/lib.rs
+++ b/src/tools/rust-analyzer/crates/flycheck/src/lib.rs
@@ -169,13 +169,17 @@ 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();
@@ -183,7 +187,12 @@ impl FlycheckActor {
                 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");