diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-04-20 21:26:25 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-20 21:26:25 +0000 |
| commit | ec645f2d75d2939a2f64959019dd916750f1ec00 (patch) | |
| tree | 561d2f7d88aa6019a44cd20c2ecdadaff344e033 | |
| parent | 0ad6b6d40763f67cc727d000f616f88a47f43d41 (diff) | |
| parent | ce382e6a79edf9c00d4e7d7c3834cde7577e6517 (diff) | |
| download | rust-ec645f2d75d2939a2f64959019dd916750f1ec00.tar.gz rust-ec645f2d75d2939a2f64959019dd916750f1ec00.zip | |
Merge #4066
4066: Fix restart missing arguments in proc-macro-srv r=edwin0cheng a=edwin0cheng cc @Veetaha Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
| -rw-r--r-- | crates/ra_proc_macro/src/process.rs | 103 |
1 files changed, 52 insertions, 51 deletions
diff --git a/crates/ra_proc_macro/src/process.rs b/crates/ra_proc_macro/src/process.rs index e24944af4b9..673f80a7ab0 100644 --- a/crates/ra_proc_macro/src/process.rs +++ b/crates/ra_proc_macro/src/process.rs @@ -9,7 +9,7 @@ use crate::rpc::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTas use io::{BufRead, BufReader}; use std::{ convert::{TryFrom, TryInto}, - ffi::OsStr, + ffi::{OsStr, OsString}, io::{self, Write}, path::{Path, PathBuf}, process::{Child, Command, Stdio}, @@ -28,56 +28,6 @@ pub(crate) struct ProcMacroProcessThread { handle: jod_thread::JoinHandle<()>, } -struct Task { - req: Request, - result_tx: Sender<Option<Response>>, -} - -struct Process { - path: PathBuf, - child: Child, -} - -impl Drop for Process { - fn drop(&mut self) { - let _ = self.child.kill(); - } -} - -impl Process { - fn run( - process_path: PathBuf, - args: impl IntoIterator<Item = impl AsRef<OsStr>>, - ) -> io::Result<Process> { - let child = Command::new(&process_path) - .args(args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::null()) - .spawn()?; - - Ok(Process { path: process_path, child }) - } - - fn restart(&mut self) -> io::Result<()> { - let _ = self.child.kill(); - self.child = Command::new(&self.path) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::null()) - .spawn()?; - Ok(()) - } - - fn stdio(&mut self) -> Option<(impl Write, impl BufRead)> { - let stdin = self.child.stdin.take()?; - let stdout = self.child.stdout.take()?; - let read = BufReader::new(stdout); - - Some((stdin, read)) - } -} - impl ProcMacroProcessSrv { pub fn run( process_path: PathBuf, @@ -192,6 +142,57 @@ fn client_loop(task_rx: Receiver<Task>, mut process: Process) { } } +struct Task { + req: Request, + result_tx: Sender<Option<Response>>, +} + +struct Process { + path: PathBuf, + args: Vec<OsString>, + child: Child, +} + +impl Drop for Process { + fn drop(&mut self) { + let _ = self.child.kill(); + } +} + +impl Process { + fn run( + path: PathBuf, + args: impl IntoIterator<Item = impl AsRef<OsStr>>, + ) -> io::Result<Process> { + let args = args.into_iter().map(|s| s.as_ref().into()).collect(); + let child = mk_child(&path, &args)?; + Ok(Process { path, args, child }) + } + + fn restart(&mut self) -> io::Result<()> { + let _ = self.child.kill(); + self.child = mk_child(&self.path, &self.args)?; + Ok(()) + } + + fn stdio(&mut self) -> Option<(impl Write, impl BufRead)> { + let stdin = self.child.stdin.take()?; + let stdout = self.child.stdout.take()?; + let read = BufReader::new(stdout); + + Some((stdin, read)) + } +} + +fn mk_child(path: &Path, args: impl IntoIterator<Item = impl AsRef<OsStr>>) -> io::Result<Child> { + Command::new(&path) + .args(args) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::null()) + .spawn() +} + fn send_request( mut writer: &mut impl Write, mut reader: &mut impl BufRead, |
