From bd350108b0d1be67e86b93a94c324317a00b57cd Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Tue, 21 Apr 2020 04:57:55 +0800 Subject: Fix restart missing arguments in proc-macro-srv --- crates/ra_proc_macro/src/process.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/crates/ra_proc_macro/src/process.rs b/crates/ra_proc_macro/src/process.rs index e24944af4..97ba196b8 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}, @@ -35,6 +35,7 @@ struct Task { struct Process { path: PathBuf, + args: Vec, child: Child, } @@ -46,22 +47,25 @@ impl Drop for Process { impl Process { fn run( - process_path: PathBuf, + path: PathBuf, args: impl IntoIterator>, ) -> io::Result { - let child = Command::new(&process_path) - .args(args) + let args = args.into_iter().map(|s| s.as_ref().into()).collect(); + + let child = Command::new(&path) + .args(&args) .stdin(Stdio::piped()) .stdout(Stdio::piped()) .stderr(Stdio::null()) .spawn()?; - Ok(Process { path: process_path, child }) + Ok(Process { path, args, child }) } fn restart(&mut self) -> io::Result<()> { let _ = self.child.kill(); self.child = Command::new(&self.path) + .args(&self.args) .stdin(Stdio::piped()) .stdout(Stdio::piped()) .stderr(Stdio::null()) -- cgit v1.2.3 From ce382e6a79edf9c00d4e7d7c3834cde7577e6517 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Tue, 21 Apr 2020 05:22:17 +0800 Subject: Refactor a bit --- crates/ra_proc_macro/src/process.rs | 105 ++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 54 deletions(-) diff --git a/crates/ra_proc_macro/src/process.rs b/crates/ra_proc_macro/src/process.rs index 97ba196b8..673f80a7a 100644 --- a/crates/ra_proc_macro/src/process.rs +++ b/crates/ra_proc_macro/src/process.rs @@ -28,60 +28,6 @@ pub(crate) struct ProcMacroProcessThread { handle: jod_thread::JoinHandle<()>, } -struct Task { - req: Request, - result_tx: Sender>, -} - -struct Process { - path: PathBuf, - args: Vec, - child: Child, -} - -impl Drop for Process { - fn drop(&mut self) { - let _ = self.child.kill(); - } -} - -impl Process { - fn run( - path: PathBuf, - args: impl IntoIterator>, - ) -> io::Result { - let args = args.into_iter().map(|s| s.as_ref().into()).collect(); - - let child = Command::new(&path) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::null()) - .spawn()?; - - Ok(Process { path, args, child }) - } - - fn restart(&mut self) -> io::Result<()> { - let _ = self.child.kill(); - self.child = Command::new(&self.path) - .args(&self.args) - .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, @@ -196,6 +142,57 @@ fn client_loop(task_rx: Receiver, mut process: Process) { } } +struct Task { + req: Request, + result_tx: Sender>, +} + +struct Process { + path: PathBuf, + args: Vec, + child: Child, +} + +impl Drop for Process { + fn drop(&mut self) { + let _ = self.child.kill(); + } +} + +impl Process { + fn run( + path: PathBuf, + args: impl IntoIterator>, + ) -> io::Result { + 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>) -> io::Result { + 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, -- cgit v1.2.3