Skip to content

Fix restart missing arguments in proc-macro-srv #4066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 52 additions & 51 deletions crates/ra_proc_macro/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down