diff options
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 | } | ||