Send a DidCancel event when restarting flychecks

This commit is contained in:
Lukas Wirth 2022-06-16 15:25:50 +02:00
parent bc1aa93e7e
commit 59799312e2

View file

@ -162,26 +162,31 @@ impl FlycheckActor {
cargo_handle.cancel(); cargo_handle.cancel();
} }
while let Ok(Restart) = inbox.recv_timeout(Duration::from_millis(50)) {} while let Ok(Restart) = inbox.recv_timeout(Duration::from_millis(50)) {}
self.progress(Progress::DidCancel);
self.cancel_check_process();
let command = self.check_command(); let command = self.check_command();
let command_f = format!("{command:?}");
tracing::debug!(?command, "will restart flycheck"); tracing::debug!(?command, "will restart flycheck");
match CargoHandle::spawn(command) { match CargoHandle::spawn(command) {
Ok(cargo_handle) => { Ok(cargo_handle) => {
tracing::debug!(%command_f, "did restart flycheck"); tracing::debug!(
command = ?self.check_command(),
"did restart flycheck"
);
self.cargo_handle = Some(cargo_handle); self.cargo_handle = Some(cargo_handle);
self.progress(Progress::DidStart); self.progress(Progress::DidStart);
} }
Err(error) => { Err(error) => {
tracing::error!(%command_f, %error, "failed to restart flycheck"); tracing::error!(
command = ?self.check_command(),
%error, "failed to restart flycheck"
);
} }
} }
} }
Event::CheckEvent(None) => { Event::CheckEvent(None) => {
// Watcher finished, replace it with a never channel to tracing::debug!("flycheck finished");
// avoid busy-waiting.
// Watcher finished
let cargo_handle = self.cargo_handle.take().unwrap(); let cargo_handle = self.cargo_handle.take().unwrap();
let res = cargo_handle.join(); let res = cargo_handle.join();
if res.is_err() { if res.is_err() {
@ -209,8 +214,10 @@ impl FlycheckActor {
// If we rerun the thread, we need to discard the previous check results first // If we rerun the thread, we need to discard the previous check results first
self.cancel_check_process(); self.cancel_check_process();
} }
fn cancel_check_process(&mut self) { fn cancel_check_process(&mut self) {
if self.cargo_handle.take().is_some() { if let Some(cargo_handle) = self.cargo_handle.take() {
cargo_handle.cancel();
self.progress(Progress::DidCancel); self.progress(Progress::DidCancel);
} }
} }