diff options
author | Edwin Cheng <[email protected]> | 2020-04-16 14:13:57 +0100 |
---|---|---|
committer | Edwin Cheng <[email protected]> | 2020-04-16 14:13:57 +0100 |
commit | 177becea98bddcd995a2abec59c6b60bac6b5a2b (patch) | |
tree | 64b7ecca11b93b71aab3e2fc0648d70aa012ee8b /crates/ra_proc_macro | |
parent | ca7dc69a8e87883c6a0c9df88c936fa2a4658c7b (diff) |
Add proc-macro cli command for rust-analyzer
Diffstat (limited to 'crates/ra_proc_macro')
-rw-r--r-- | crates/ra_proc_macro/src/lib.rs | 7 | ||||
-rw-r--r-- | crates/ra_proc_macro/src/process.rs | 8 |
2 files changed, 10 insertions, 5 deletions
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 { | |||
56 | } | 56 | } |
57 | 57 | ||
58 | impl ProcMacroClient { | 58 | impl ProcMacroClient { |
59 | pub fn extern_process(process_path: &Path) -> Result<ProcMacroClient, std::io::Error> { | 59 | pub fn extern_process<T: AsRef<str>>( |
60 | let (thread, process) = ProcMacroProcessSrv::run(process_path)?; | 60 | process_path: &Path, |
61 | args: &[T], | ||
62 | ) -> Result<ProcMacroClient, std::io::Error> { | ||
63 | let (thread, process) = ProcMacroProcessSrv::run(process_path, args)?; | ||
61 | Ok(ProcMacroClient { | 64 | Ok(ProcMacroClient { |
62 | kind: ProcMacroClientKind::Process { process: Arc::new(process), thread }, | 65 | kind: ProcMacroClientKind::Process { process: Arc::new(process), thread }, |
63 | }) | 66 | }) |
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 { | |||
44 | } | 44 | } |
45 | 45 | ||
46 | impl Process { | 46 | impl Process { |
47 | fn run(process_path: &Path) -> Result<Process, io::Error> { | 47 | fn run<T: AsRef<str>>(process_path: &Path, args: &[T]) -> Result<Process, io::Error> { |
48 | let child = Command::new(process_path.clone()) | 48 | let child = Command::new(process_path.clone()) |
49 | .args(args.iter().map(|it| it.as_ref())) | ||
49 | .stdin(Stdio::piped()) | 50 | .stdin(Stdio::piped()) |
50 | .stdout(Stdio::piped()) | 51 | .stdout(Stdio::piped()) |
51 | .stderr(Stdio::null()) | 52 | .stderr(Stdio::null()) |
@@ -74,10 +75,11 @@ impl Process { | |||
74 | } | 75 | } |
75 | 76 | ||
76 | impl ProcMacroProcessSrv { | 77 | impl ProcMacroProcessSrv { |
77 | pub fn run( | 78 | pub fn run<T: AsRef<str>>( |
78 | process_path: &Path, | 79 | process_path: &Path, |
80 | args: &[T], | ||
79 | ) -> Result<(ProcMacroProcessThread, ProcMacroProcessSrv), io::Error> { | 81 | ) -> Result<(ProcMacroProcessThread, ProcMacroProcessSrv), io::Error> { |
80 | let process = Process::run(process_path)?; | 82 | let process = Process::run(process_path, args)?; |
81 | 83 | ||
82 | let (task_tx, task_rx) = bounded(0); | 84 | let (task_tx, task_rx) = bounded(0); |
83 | let handle = jod_thread::spawn(move || { | 85 | let handle = jod_thread::spawn(move || { |