diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-04-16 21:21:59 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-04-16 21:21:59 +0100 |
commit | 10d8cb913cb8247ae64b954cf07460f1b6d96ef7 (patch) | |
tree | 976786b86c189d8c03a15378fd62526cbe8eaab7 /crates/ra_proc_macro/src | |
parent | a4cda3efbbabe4c6129de4dc095953fe858d7d3f (diff) | |
parent | 16a74cfd234e94d383b0ef067fb6a3c651ed9624 (diff) |
Merge #3958
3958: Add proc-macro related config and tests r=matklad a=edwin0cheng
This PR do the following things:
1. Add cli argument `proc-macro` for running proc-macro server.
2. Added support for proc-macro in bench and analysis-stats
3. Added typescript config for proc-macros
4. Added an heavy test for proc-macros.
To test it out:
1. run `cargo xtask install --proc-macro`
2. add `"rust-analyzer.cargo.loadOutDirsFromCheck": true"` and `"rust-analyzer.procMacro.enabled": true"` in vs code config.
[Edit] Change to use `rust-analyzer proc-macro` for running proc-macro standalone process.
Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_proc_macro/src')
-rw-r--r-- | crates/ra_proc_macro/src/lib.rs | 12 | ||||
-rw-r--r-- | crates/ra_proc_macro/src/process.rs | 19 |
2 files changed, 25 insertions, 6 deletions
diff --git a/crates/ra_proc_macro/src/lib.rs b/crates/ra_proc_macro/src/lib.rs index 63da9f1b4..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; | |||
12 | use process::{ProcMacroProcessSrv, ProcMacroProcessThread}; | 12 | use process::{ProcMacroProcessSrv, ProcMacroProcessThread}; |
13 | use ra_tt::{SmolStr, Subtree}; | 13 | use ra_tt::{SmolStr, Subtree}; |
14 | use std::{ | 14 | use std::{ |
15 | ffi::OsStr, | ||
15 | path::{Path, PathBuf}, | 16 | path::{Path, PathBuf}, |
16 | sync::Arc, | 17 | sync::Arc, |
17 | }; | 18 | }; |
@@ -56,8 +57,15 @@ pub struct ProcMacroClient { | |||
56 | } | 57 | } |
57 | 58 | ||
58 | impl ProcMacroClient { | 59 | impl ProcMacroClient { |
59 | pub fn extern_process(process_path: &Path) -> Result<ProcMacroClient, std::io::Error> { | 60 | pub fn extern_process<I, S>( |
60 | let (thread, process) = ProcMacroProcessSrv::run(process_path)?; | 61 | process_path: &Path, |
62 | args: I, | ||
63 | ) -> Result<ProcMacroClient, std::io::Error> | ||
64 | where | ||
65 | I: IntoIterator<Item = S>, | ||
66 | S: AsRef<OsStr>, | ||
67 | { | ||
68 | let (thread, process) = ProcMacroProcessSrv::run(process_path, args)?; | ||
61 | Ok(ProcMacroClient { | 69 | Ok(ProcMacroClient { |
62 | kind: ProcMacroClientKind::Process { process: Arc::new(process), thread }, | 70 | kind: ProcMacroClientKind::Process { process: Arc::new(process), thread }, |
63 | }) | 71 | }) |
diff --git a/crates/ra_proc_macro/src/process.rs b/crates/ra_proc_macro/src/process.rs index e8c85be38..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 | |||
9 | use io::{BufRead, BufReader}; | 9 | use io::{BufRead, BufReader}; |
10 | use std::{ | 10 | use std::{ |
11 | convert::{TryFrom, TryInto}, | 11 | convert::{TryFrom, TryInto}, |
12 | ffi::OsStr, | ||
12 | io::{self, Write}, | 13 | io::{self, Write}, |
13 | path::{Path, PathBuf}, | 14 | path::{Path, PathBuf}, |
14 | process::{Child, Command, Stdio}, | 15 | process::{Child, Command, Stdio}, |
@@ -44,8 +45,13 @@ impl Drop for Process { | |||
44 | } | 45 | } |
45 | 46 | ||
46 | impl Process { | 47 | impl Process { |
47 | fn run(process_path: &Path) -> Result<Process, io::Error> { | 48 | fn run<I, S>(process_path: &Path, args: I) -> Result<Process, io::Error> |
49 | where | ||
50 | I: IntoIterator<Item = S>, | ||
51 | S: AsRef<OsStr>, | ||
52 | { | ||
48 | let child = Command::new(process_path.clone()) | 53 | let child = Command::new(process_path.clone()) |
54 | .args(args) | ||
49 | .stdin(Stdio::piped()) | 55 | .stdin(Stdio::piped()) |
50 | .stdout(Stdio::piped()) | 56 | .stdout(Stdio::piped()) |
51 | .stderr(Stdio::null()) | 57 | .stderr(Stdio::null()) |
@@ -74,10 +80,15 @@ impl Process { | |||
74 | } | 80 | } |
75 | 81 | ||
76 | impl ProcMacroProcessSrv { | 82 | impl ProcMacroProcessSrv { |
77 | pub fn run( | 83 | pub fn run<I, S>( |
78 | process_path: &Path, | 84 | process_path: &Path, |
79 | ) -> Result<(ProcMacroProcessThread, ProcMacroProcessSrv), io::Error> { | 85 | args: I, |
80 | let process = Process::run(process_path)?; | 86 | ) -> Result<(ProcMacroProcessThread, ProcMacroProcessSrv), io::Error> |
87 | where | ||
88 | I: IntoIterator<Item = S>, | ||
89 | S: AsRef<OsStr>, | ||
90 | { | ||
91 | let process = Process::run(process_path, args)?; | ||
81 | 92 | ||
82 | let (task_tx, task_rx) = bounded(0); | 93 | let (task_tx, task_rx) = bounded(0); |
83 | let handle = jod_thread::spawn(move || { | 94 | let handle = jod_thread::spawn(move || { |