Unnamed repository; edit this file 'description' to name the repository.
Polish
Lukas Wirth 2022-06-15
parent 6438ef9 · commit bc1aa93
-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 4ff49cc805..e327476f3b 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 c52601898d..66fa25ec23 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");