From b4c5ee33ae128df4e82c992d0c13f6c9df0f9f02 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 17 Apr 2020 04:08:01 +0800 Subject: Fix extern_process args --- crates/ra_proc_macro/src/lib.rs | 11 ++++++++--- crates/ra_proc_macro/src/process.rs | 19 ++++++++++++++----- 2 files changed, 22 insertions(+), 8 deletions(-) (limited to 'crates/ra_proc_macro/src') diff --git a/crates/ra_proc_macro/src/lib.rs b/crates/ra_proc_macro/src/lib.rs index 14a675db2..b200fd126 100644 --- a/crates/ra_proc_macro/src/lib.rs +++ b/crates/ra_proc_macro/src/lib.rs @@ -12,6 +12,7 @@ pub mod msg; use process::{ProcMacroProcessSrv, ProcMacroProcessThread}; use ra_tt::{SmolStr, Subtree}; use std::{ + ffi::OsStr, path::{Path, PathBuf}, sync::Arc, }; @@ -56,10 +57,14 @@ pub struct ProcMacroClient { } impl ProcMacroClient { - pub fn extern_process>( + pub fn extern_process( process_path: &Path, - args: &[T], - ) -> Result { + args: I, + ) -> Result + where + I: IntoIterator, + S: AsRef, + { let (thread, process) = ProcMacroProcessSrv::run(process_path, args)?; Ok(ProcMacroClient { kind: ProcMacroClientKind::Process { process: Arc::new(process), thread }, diff --git a/crates/ra_proc_macro/src/process.rs b/crates/ra_proc_macro/src/process.rs index b5e8493ac..f851570bc 100644 --- a/crates/ra_proc_macro/src/process.rs +++ b/crates/ra_proc_macro/src/process.rs @@ -9,6 +9,7 @@ use crate::rpc::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTas use io::{BufRead, BufReader}; use std::{ convert::{TryFrom, TryInto}, + ffi::OsStr, io::{self, Write}, path::{Path, PathBuf}, process::{Child, Command, Stdio}, @@ -44,9 +45,13 @@ impl Drop for Process { } impl Process { - fn run>(process_path: &Path, args: &[T]) -> Result { + fn run(process_path: &Path, args: I) -> Result + where + I: IntoIterator, + S: AsRef, + { let child = Command::new(process_path.clone()) - .args(args.iter().map(|it| it.as_ref())) + .args(args) .stdin(Stdio::piped()) .stdout(Stdio::piped()) .stderr(Stdio::null()) @@ -75,10 +80,14 @@ impl Process { } impl ProcMacroProcessSrv { - pub fn run>( + pub fn run( process_path: &Path, - args: &[T], - ) -> Result<(ProcMacroProcessThread, ProcMacroProcessSrv), io::Error> { + args: I, + ) -> Result<(ProcMacroProcessThread, ProcMacroProcessSrv), io::Error> + where + I: IntoIterator, + S: AsRef, + { let process = Process::run(process_path, args)?; let (task_tx, task_rx) = bounded(0); -- cgit v1.2.3