diff options
Diffstat (limited to 'support/texlab/crates/commands/src')
-rw-r--r-- | support/texlab/crates/commands/src/build.rs | 55 | ||||
-rw-r--r-- | support/texlab/crates/commands/src/fwd_search.rs | 3 |
2 files changed, 48 insertions, 10 deletions
diff --git a/support/texlab/crates/commands/src/build.rs b/support/texlab/crates/commands/src/build.rs index 3d93601e39..47e156ef72 100644 --- a/support/texlab/crates/commands/src/build.rs +++ b/support/texlab/crates/commands/src/build.rs @@ -1,7 +1,7 @@ use std::{ io::{BufReader, Read}, path::{Path, PathBuf}, - process::{ExitStatus, Stdio}, + process::{Child, Stdio}, thread::{self, JoinHandle}, }; @@ -64,7 +64,7 @@ impl BuildCommand { }) } - pub fn run(self, sender: Sender<String>) -> Result<ExitStatus, BuildError> { + pub fn spawn(self, sender: Sender<String>) -> Result<Child, BuildError> { log::debug!( "Spawning compiler {} {:#?} in directory {}", self.program, @@ -72,19 +72,56 @@ impl BuildCommand { self.working_dir.display() ); - let mut process = std::process::Command::new(&self.program) - .args(self.args) + let mut process = self.spawn_internal()?; + track_output(process.stderr.take().unwrap(), sender.clone()); + track_output(process.stdout.take().unwrap(), sender); + Ok(process) + } + + #[cfg(windows)] + fn spawn_internal(&self) -> Result<Child, BuildError> { + std::process::Command::new(&self.program) + .args(self.args.clone()) .stdin(Stdio::null()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) .current_dir(&self.working_dir) - .spawn()?; + .spawn() + .map_err(Into::into) + } - track_output(process.stderr.take().unwrap(), sender.clone()); - track_output(process.stdout.take().unwrap(), sender); + #[cfg(unix)] + fn spawn_internal(&self) -> Result<Child, BuildError> { + use std::os::unix::process::CommandExt; + std::process::Command::new(&self.program) + .args(self.args.clone()) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .current_dir(&self.working_dir) + .process_group(0) + .spawn() + .map_err(Into::into) + } + + #[cfg(windows)] + pub fn cancel(pid: u32) -> std::io::Result<bool> { + Ok(std::process::Command::new("taskkill") + .arg("/PID") + .arg(pid.to_string()) + .arg("/F") + .arg("/T") + .status()? + .success()) + } + + #[cfg(not(windows))] + pub fn cancel(pid: u32) -> Result<bool> { + unsafe { + libc::killpg(pid as libc::pid_t, libc::SIGTERM); + } - let status = process.wait(); - Ok(status?) + Ok(true) } } diff --git a/support/texlab/crates/commands/src/fwd_search.rs b/support/texlab/crates/commands/src/fwd_search.rs index c458f33cf1..fc0a130f86 100644 --- a/support/texlab/crates/commands/src/fwd_search.rs +++ b/support/texlab/crates/commands/src/fwd_search.rs @@ -32,6 +32,7 @@ pub enum ForwardSearchError { LaunchViewer(#[from] std::io::Error), } +#[derive(Debug)] pub struct ForwardSearch { program: String, args: Vec<String>, @@ -79,7 +80,7 @@ impl ForwardSearch { let tex_path = tex_path.to_string_lossy().into_owned(); let pdf_path = pdf_path.to_string_lossy().into_owned(); - let line = line.unwrap_or_else(|| child.line_index.line_col(child.cursor).line); + let line = line.unwrap_or_else(|| child.cursor.line); let line = (line + 1).to_string(); let program = config.program.clone(); |