]> git.lizzy.rs Git - rust.git/blobdiff - src/tools/rust-analyzer/crates/flycheck/src/lib.rs
:arrow_up: rust-analyzer
[rust.git] / src / tools / rust-analyzer / crates / flycheck / src / lib.rs
index 3347940ec6d639015304407bdd708dcff184c2bb..c22945c81fcb93b1971721c6d5f6446cf950142c 100644 (file)
@@ -77,8 +77,13 @@ pub fn spawn(
     }
 
     /// Schedule a re-start of the cargo check worker.
-    pub fn update(&self) {
-        self.sender.send(Restart).unwrap();
+    pub fn restart(&self) {
+        self.sender.send(Restart::Yes).unwrap();
+    }
+
+    /// Stop this cargo check worker.
+    pub fn cancel(&self) {
+        self.sender.send(Restart::No).unwrap();
     }
 
     pub fn id(&self) -> usize {
@@ -122,7 +127,10 @@ pub enum Progress {
     DidCancel,
 }
 
-struct Restart;
+enum Restart {
+    Yes,
+    No,
+}
 
 struct FlycheckActor {
     id: usize,
@@ -149,6 +157,7 @@ fn new(
         config: FlycheckConfig,
         workspace_root: AbsPathBuf,
     ) -> FlycheckActor {
+        tracing::info!(%id, ?workspace_root, "Spawning flycheck");
         FlycheckActor { id, sender, config, workspace_root, cargo_handle: None }
     }
     fn progress(&self, progress: Progress) {
@@ -164,10 +173,13 @@ fn next_event(&self, inbox: &Receiver<Restart>) -> Option<Event> {
     fn run(mut self, inbox: Receiver<Restart>) {
         while let Some(event) = self.next_event(&inbox) {
             match event {
-                Event::Restart(Restart) => {
+                Event::Restart(Restart::No) => {
+                    self.cancel_check_process();
+                }
+                Event::Restart(Restart::Yes) => {
                     // Cancel the previously spawned process
                     self.cancel_check_process();
-                    while let Ok(Restart) = inbox.recv_timeout(Duration::from_millis(50)) {}
+                    while let Ok(_) = inbox.recv_timeout(Duration::from_millis(50)) {}
 
                     let command = self.check_command();
                     tracing::debug!(?command, "will restart flycheck");
@@ -223,6 +235,10 @@ fn run(mut self, inbox: Receiver<Restart>) {
 
     fn cancel_check_process(&mut self) {
         if let Some(cargo_handle) = self.cargo_handle.take() {
+            tracing::debug!(
+                command = ?self.check_command(),
+                "did  cancel flycheck"
+            );
             cargo_handle.cancel();
             self.progress(Progress::DidCancel);
         }
@@ -345,7 +361,7 @@ fn run(self) -> io::Result<(bool, String)> {
         //
         // Because cargo only outputs one JSON object per line, we can
         // simply skip a line if it doesn't parse, which just ignores any
-        // erroneus output.
+        // erroneous output.
 
         let mut error = String::new();
         let mut read_at_least_one_message = false;