From 177becea98bddcd995a2abec59c6b60bac6b5a2b Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Thu, 16 Apr 2020 21:13:57 +0800 Subject: Add proc-macro cli command for rust-analyzer --- crates/ra_proc_macro/src/lib.rs | 7 +++++-- crates/ra_proc_macro/src/process.rs | 8 +++++--- 2 files changed, 10 insertions(+), 5 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 63da9f1b4..14a675db2 100644 --- a/crates/ra_proc_macro/src/lib.rs +++ b/crates/ra_proc_macro/src/lib.rs @@ -56,8 +56,11 @@ pub struct ProcMacroClient { } impl ProcMacroClient { - pub fn extern_process(process_path: &Path) -> Result { - let (thread, process) = ProcMacroProcessSrv::run(process_path)?; + pub fn extern_process>( + process_path: &Path, + args: &[T], + ) -> Result { + 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 e8c85be38..b5e8493ac 100644 --- a/crates/ra_proc_macro/src/process.rs +++ b/crates/ra_proc_macro/src/process.rs @@ -44,8 +44,9 @@ impl Drop for Process { } impl Process { - fn run(process_path: &Path) -> Result { + fn run>(process_path: &Path, args: &[T]) -> Result { let child = Command::new(process_path.clone()) + .args(args.iter().map(|it| it.as_ref())) .stdin(Stdio::piped()) .stdout(Stdio::piped()) .stderr(Stdio::null()) @@ -74,10 +75,11 @@ impl Process { } impl ProcMacroProcessSrv { - pub fn run( + pub fn run>( process_path: &Path, + args: &[T], ) -> Result<(ProcMacroProcessThread, ProcMacroProcessSrv), io::Error> { - let process = Process::run(process_path)?; + let process = Process::run(process_path, args)?; let (task_tx, task_rx) = bounded(0); let handle = jod_thread::spawn(move || { -- cgit v1.2.3 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