Rename CargoHandle to CommandHandle
This handle wraps an arbitrary command, which might be a rustc command rather than cargo.
This commit is contained in:
parent
54c4125086
commit
14078ed303
@ -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<CargoHandle>,
|
||||
command_handle: Option<CommandHandle>,
|
||||
}
|
||||
|
||||
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<StateChange>) -> Option<Event> {
|
||||
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<StateChange>) {
|
||||
|
||||
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<StateChange>) {
|
||||
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<StateChange>) {
|
||||
}
|
||||
|
||||
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<CargoMessage>,
|
||||
}
|
||||
|
||||
impl CargoHandle {
|
||||
fn spawn(mut command: Command) -> std::io::Result<CargoHandle> {
|
||||
impl CommandHandle {
|
||||
fn spawn(mut command: Command) -> std::io::Result<CommandHandle> {
|
||||
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<CargoHandle> {
|
||||
.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) {
|
||||
|
Loading…
Reference in New Issue
Block a user