diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-03-26 17:09:32 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-03-26 17:09:32 +0000 |
commit | b1594f108041813c9fa32538950c15c55202cbd5 (patch) | |
tree | cef1e662a7acf2807422e7c232014c5326ac37b6 /crates/ra_proc_macro/src | |
parent | 20c110e57f24aa54154942ee40921e9129fbc595 (diff) | |
parent | db162df264a222021dbc7f1f93af94029f3948d9 (diff) |
Merge #3727
3727: Introduce ra_proc_macro r=matklad a=edwin0cheng
This PR implemented:
1. Reading dylib path of proc-macro crate from cargo check , similar to how `OUTDIR` is obtained.
2. Added a new crate `ra_proc_macro` and implement the foot-work for reading result from external proc-macro expander.
3. Added a struct `ProcMacroClient` , which will be responsible to the client side communication to the External 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 | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/crates/ra_proc_macro/src/lib.rs b/crates/ra_proc_macro/src/lib.rs new file mode 100644 index 000000000..5e21dd487 --- /dev/null +++ b/crates/ra_proc_macro/src/lib.rs | |||
@@ -0,0 +1,59 @@ | |||
1 | //! Client-side Proc-Macro crate | ||
2 | //! | ||
3 | //! We separate proc-macro expanding logic to an extern program to allow | ||
4 | //! different implementations (e.g. wasm or dylib loading). And this crate | ||
5 | //! is used to provide basic infrastructure for communication between two | ||
6 | //! processes: Client (RA itself), Server (the external program) | ||
7 | |||
8 | use ra_tt::{SmolStr, Subtree}; | ||
9 | use std::{ | ||
10 | path::{Path, PathBuf}, | ||
11 | sync::Arc, | ||
12 | }; | ||
13 | |||
14 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
15 | pub struct ProcMacroProcessExpander { | ||
16 | process: Arc<ProcMacroProcessSrv>, | ||
17 | name: SmolStr, | ||
18 | } | ||
19 | |||
20 | impl ra_tt::TokenExpander for ProcMacroProcessExpander { | ||
21 | fn expand( | ||
22 | &self, | ||
23 | _subtree: &Subtree, | ||
24 | _attr: Option<&Subtree>, | ||
25 | ) -> Result<Subtree, ra_tt::ExpansionError> { | ||
26 | // FIXME: do nothing for now | ||
27 | Ok(Subtree::default()) | ||
28 | } | ||
29 | } | ||
30 | |||
31 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
32 | pub struct ProcMacroProcessSrv { | ||
33 | path: PathBuf, | ||
34 | } | ||
35 | |||
36 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
37 | pub enum ProcMacroClient { | ||
38 | Process { process: Arc<ProcMacroProcessSrv> }, | ||
39 | Dummy, | ||
40 | } | ||
41 | |||
42 | impl ProcMacroClient { | ||
43 | pub fn extern_process(process_path: &Path) -> ProcMacroClient { | ||
44 | let process = ProcMacroProcessSrv { path: process_path.into() }; | ||
45 | ProcMacroClient::Process { process: Arc::new(process) } | ||
46 | } | ||
47 | |||
48 | pub fn dummy() -> ProcMacroClient { | ||
49 | ProcMacroClient::Dummy | ||
50 | } | ||
51 | |||
52 | pub fn by_dylib_path( | ||
53 | &self, | ||
54 | _dylib_path: &Path, | ||
55 | ) -> Vec<(SmolStr, Arc<dyn ra_tt::TokenExpander>)> { | ||
56 | // FIXME: return empty for now | ||
57 | vec![] | ||
58 | } | ||
59 | } | ||