about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2022-06-15 18:35:48 +0200
committerLukas Wirth <lukastw97@gmail.com>2022-06-15 18:35:48 +0200
commitbc1aa93e7e85b11325cdd49c46aec23042efb180 (patch)
treebe1390bf4ba7c37720c22cbf3dcea1d92e599a3e
parent6438ef9aa3eec59f413e89278519df38646baeb0 (diff)
downloadrust-bc1aa93e7e85b11325cdd49c46aec23042efb180.tar.gz
rust-bc1aa93e7e85b11325cdd49c46aec23042efb180.zip
Polish
-rw-r--r--crates/flycheck/src/lib.rs23
-rw-r--r--crates/stdx/src/lib.rs10
2 files changed, 18 insertions, 15 deletions
diff --git a/crates/flycheck/src/lib.rs b/crates/flycheck/src/lib.rs
index 4ff49cc8053..e327476f3bc 100644
--- a/crates/flycheck/src/lib.rs
+++ b/crates/flycheck/src/lib.rs
@@ -157,22 +157,25 @@ impl FlycheckActor {
         while let Some(event) = self.next_event(&inbox) {
             match event {
                 Event::Restart(Restart) => {
-                    // Drop and cancel the previously spawned process
-                    self.cargo_handle.take();
+                    if let Some(cargo_handle) = self.cargo_handle.take() {
+                        // Cancel the previously spawned process
+                        cargo_handle.cancel();
+                    }
                     while let Ok(Restart) = inbox.recv_timeout(Duration::from_millis(50)) {}
 
                     self.cancel_check_process();
 
                     let command = self.check_command();
-                    let command_f = format!("restart flycheck {command:?}");
+                    let command_f = format!("{command:?}");
+                    tracing::debug!(?command, "will restart flycheck");
                     match CargoHandle::spawn(command) {
                         Ok(cargo_handle) => {
-                            tracing::info!("{}", command_f);
+                            tracing::debug!(%command_f, "did  restart flycheck");
                             self.cargo_handle = Some(cargo_handle);
                             self.progress(Progress::DidStart);
                         }
-                        Err(e) => {
-                            tracing::error!("{command_f} failed: {e:?}",);
+                        Err(error) => {
+                            tracing::error!(%command_f, %error, "failed to restart flycheck");
                         }
                     }
                 }
@@ -289,7 +292,13 @@ impl CargoHandle {
         Ok(CargoHandle { child, thread, receiver })
     }
 
-    fn join(self) -> io::Result<()> {
+    fn cancel(mut self) {
+        let _ = self.child.kill();
+        let _ = self.child.wait();
+    }
+
+    fn join(mut self) -> io::Result<()> {
+        let _ = self.child.kill();
         let exit_status = self.child.wait()?;
         let (read_at_least_one_message, error) = self.thread.join()?;
         if read_at_least_one_message || exit_status.success() {
diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs
index c52601898d7..66fa25ec231 100644
--- a/crates/stdx/src/lib.rs
+++ b/crates/stdx/src/lib.rs
@@ -1,7 +1,7 @@
 //! Missing batteries for standard libraries.
-use std::iter;
 use std::process::Command;
 use std::{cmp::Ordering, ops, time::Instant};
+use std::{io as sio, iter};
 
 mod macros;
 pub mod process;
@@ -159,16 +159,10 @@ impl Drop for JodChild {
 }
 
 impl JodChild {
-    pub fn spawn(mut command: Command) -> std::io::Result<Self> {
+    pub fn spawn(mut command: Command) -> sio::Result<Self> {
         command.spawn().map(Self)
     }
 
-    pub fn wait(self) -> std::io::Result<std::process::ExitStatus> {
-        let mut inner = self.into_inner();
-        let _ = inner.kill();
-        inner.wait()
-    }
-
     pub fn into_inner(self) -> std::process::Child {
         if cfg!(target_arch = "wasm32") {
             panic!("no processes on wasm");