From 14078ed303c80bc6d4b1b5f441bbb1e04a1f3adf Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Tue, 15 Aug 2023 15:58:21 -0700 Subject: [PATCH] Rename CargoHandle to CommandHandle This handle wraps an arbitrary command, which might be a rustc command rather than cargo. --- crates/flycheck/src/lib.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/crates/flycheck/src/lib.rs b/crates/flycheck/src/lib.rs index fbb943ccb99..7c52eb0b5be 100644 --- a/crates/flycheck/src/lib.rs +++ b/crates/flycheck/src/lib.rs @@ -168,7 +168,7 @@ struct FlycheckActor { /// doesn't provide a way to read sub-process output without blocking, so we /// have to wrap sub-processes output handling in a thread and pass messages /// back over a channel. - cargo_handle: Option, + command_handle: Option, } enum Event { @@ -184,7 +184,7 @@ fn new( workspace_root: AbsPathBuf, ) -> FlycheckActor { tracing::info!(%id, ?workspace_root, "Spawning flycheck"); - FlycheckActor { id, sender, config, root: workspace_root, cargo_handle: None } + FlycheckActor { id, sender, config, root: workspace_root, command_handle: None } } fn report_progress(&self, progress: Progress) { @@ -192,7 +192,7 @@ fn report_progress(&self, progress: Progress) { } fn next_event(&self, inbox: &Receiver) -> Option { - let check_chan = self.cargo_handle.as_ref().map(|cargo| &cargo.receiver); + let check_chan = self.command_handle.as_ref().map(|cargo| &cargo.receiver); if let Ok(msg) = inbox.try_recv() { // give restarts a preference so check outputs don't block a restart or stop return Some(Event::RequestStateChange(msg)); @@ -222,13 +222,13 @@ fn run(mut self, inbox: Receiver) { let command = self.check_command(); tracing::debug!(?command, "will restart flycheck"); - match CargoHandle::spawn(command) { - Ok(cargo_handle) => { + match CommandHandle::spawn(command) { + Ok(command_handle) => { tracing::debug!( command = ?self.check_command(), "did restart flycheck" ); - self.cargo_handle = Some(cargo_handle); + self.command_handle = Some(command_handle); self.report_progress(Progress::DidStart); } Err(error) => { @@ -244,8 +244,8 @@ fn run(mut self, inbox: Receiver) { tracing::debug!(flycheck_id = self.id, "flycheck finished"); // Watcher finished - let cargo_handle = self.cargo_handle.take().unwrap(); - let res = cargo_handle.join(); + let command_handle = self.command_handle.take().unwrap(); + let res = command_handle.join(); if res.is_err() { tracing::error!( "Flycheck failed to run the following command: {:?}", @@ -284,12 +284,12 @@ fn run(mut self, inbox: Receiver) { } fn cancel_check_process(&mut self) { - if let Some(cargo_handle) = self.cargo_handle.take() { + if let Some(command_handle) = self.command_handle.take() { tracing::debug!( command = ?self.check_command(), "did cancel flycheck" ); - cargo_handle.cancel(); + command_handle.cancel(); self.report_progress(Progress::DidCancel); } } @@ -391,7 +391,7 @@ fn drop(&mut self) { } /// A handle to a cargo process used for fly-checking. -struct CargoHandle { +struct CommandHandle { /// The handle to the actual cargo process. As we cannot cancel directly from with /// a read syscall dropping and therefore terminating the process is our best option. child: JodGroupChild, @@ -399,8 +399,8 @@ struct CargoHandle { receiver: Receiver, } -impl CargoHandle { - fn spawn(mut command: Command) -> std::io::Result { +impl CommandHandle { + fn spawn(mut command: Command) -> std::io::Result { command.stdout(Stdio::piped()).stderr(Stdio::piped()).stdin(Stdio::null()); let mut child = command.group_spawn().map(JodGroupChild)?; @@ -413,7 +413,7 @@ fn spawn(mut command: Command) -> std::io::Result { .name("CargoHandle".to_owned()) .spawn(move || actor.run()) .expect("failed to spawn thread"); - Ok(CargoHandle { child, thread, receiver }) + Ok(CommandHandle { child, thread, receiver }) } fn cancel(mut self) {