Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit bc1aa93

Browse files
committed
Polish
1 parent 6438ef9 commit bc1aa93

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

crates/flycheck/src/lib.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,22 +157,25 @@ impl FlycheckActor {
157157
while let Some(event) = self.next_event(&inbox) {
158158
match event {
159159
Event::Restart(Restart) => {
160-
// Drop and cancel the previously spawned process
161-
self.cargo_handle.take();
160+
if let Some(cargo_handle) = self.cargo_handle.take() {
161+
// Cancel the previously spawned process
162+
cargo_handle.cancel();
163+
}
162164
while let Ok(Restart) = inbox.recv_timeout(Duration::from_millis(50)) {}
163165

164166
self.cancel_check_process();
165167

166168
let command = self.check_command();
167-
let command_f = format!("restart flycheck {command:?}");
169+
let command_f = format!("{command:?}");
170+
tracing::debug!(?command, "will restart flycheck");
168171
match CargoHandle::spawn(command) {
169172
Ok(cargo_handle) => {
170-
tracing::info!("{}", command_f);
173+
tracing::debug!(%command_f, "did restart flycheck");
171174
self.cargo_handle = Some(cargo_handle);
172175
self.progress(Progress::DidStart);
173176
}
174-
Err(e) => {
175-
tracing::error!("{command_f} failed: {e:?}",);
177+
Err(error) => {
178+
tracing::error!(%command_f, %error, "failed to restart flycheck");
176179
}
177180
}
178181
}
@@ -289,7 +292,13 @@ impl CargoHandle {
289292
Ok(CargoHandle { child, thread, receiver })
290293
}
291294

292-
fn join(self) -> io::Result<()> {
295+
fn cancel(mut self) {
296+
let _ = self.child.kill();
297+
let _ = self.child.wait();
298+
}
299+
300+
fn join(mut self) -> io::Result<()> {
301+
let _ = self.child.kill();
293302
let exit_status = self.child.wait()?;
294303
let (read_at_least_one_message, error) = self.thread.join()?;
295304
if read_at_least_one_message || exit_status.success() {

crates/stdx/src/lib.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Missing batteries for standard libraries.
2-
use std::iter;
32
use std::process::Command;
43
use std::{cmp::Ordering, ops, time::Instant};
4+
use std::{io as sio, iter};
55

66
mod macros;
77
pub mod process;
@@ -159,16 +159,10 @@ impl Drop for JodChild {
159159
}
160160

161161
impl JodChild {
162-
pub fn spawn(mut command: Command) -> std::io::Result<Self> {
162+
pub fn spawn(mut command: Command) -> sio::Result<Self> {
163163
command.spawn().map(Self)
164164
}
165165

166-
pub fn wait(self) -> std::io::Result<std::process::ExitStatus> {
167-
let mut inner = self.into_inner();
168-
let _ = inner.kill();
169-
inner.wait()
170-
}
171-
172166
pub fn into_inner(self) -> std::process::Child {
173167
if cfg!(target_arch = "wasm32") {
174168
panic!("no processes on wasm");

0 commit comments

Comments
 (0)