diff options
author | Edwin Cheng <[email protected]> | 2020-03-26 16:41:44 +0000 |
---|---|---|
committer | Edwin Cheng <[email protected]> | 2020-03-26 16:46:40 +0000 |
commit | db162df264a222021dbc7f1f93af94029f3948d9 (patch) | |
tree | 86f91e30f85c2c4f5faa5054b84265ddb64636d5 /crates/ra_proc_macro/src | |
parent | 72e68d0caf6e813a19a8d434fb650574b73dbc0a (diff) |
Remove deps on tt_mbe
Diffstat (limited to 'crates/ra_proc_macro/src')
-rw-r--r-- | crates/ra_proc_macro/src/lib.rs | 44 |
1 files changed, 10 insertions, 34 deletions
diff --git a/crates/ra_proc_macro/src/lib.rs b/crates/ra_proc_macro/src/lib.rs index b7fb641c3..5e21dd487 100644 --- a/crates/ra_proc_macro/src/lib.rs +++ b/crates/ra_proc_macro/src/lib.rs | |||
@@ -5,56 +5,29 @@ | |||
5 | //! is used to provide basic infrastructure for communication between two | 5 | //! is used to provide basic infrastructure for communication between two |
6 | //! processes: Client (RA itself), Server (the external program) | 6 | //! processes: Client (RA itself), Server (the external program) |
7 | 7 | ||
8 | use ra_mbe::ExpandError; | 8 | use ra_tt::{SmolStr, Subtree}; |
9 | use ra_tt::Subtree; | ||
10 | use std::{ | 9 | use std::{ |
11 | path::{Path, PathBuf}, | 10 | path::{Path, PathBuf}, |
12 | sync::Arc, | 11 | sync::Arc, |
13 | }; | 12 | }; |
14 | 13 | ||
15 | trait ProcMacroExpander: std::fmt::Debug + Send + Sync + std::panic::RefUnwindSafe { | ||
16 | fn custom_derive(&self, subtree: &Subtree, derive_name: &str) -> Result<Subtree, ExpandError>; | ||
17 | } | ||
18 | |||
19 | #[derive(Debug, Clone, PartialEq, Eq)] | 14 | #[derive(Debug, Clone, PartialEq, Eq)] |
20 | pub struct ProcMacroProcessExpander { | 15 | pub struct ProcMacroProcessExpander { |
21 | process: Arc<ProcMacroProcessSrv>, | 16 | process: Arc<ProcMacroProcessSrv>, |
17 | name: SmolStr, | ||
22 | } | 18 | } |
23 | 19 | ||
24 | impl ProcMacroExpander for ProcMacroProcessExpander { | 20 | impl ra_tt::TokenExpander for ProcMacroProcessExpander { |
25 | fn custom_derive( | 21 | fn expand( |
26 | &self, | 22 | &self, |
27 | _subtree: &Subtree, | 23 | _subtree: &Subtree, |
28 | _derive_name: &str, | 24 | _attr: Option<&Subtree>, |
29 | ) -> Result<Subtree, ExpandError> { | 25 | ) -> Result<Subtree, ra_tt::ExpansionError> { |
30 | // FIXME: do nothing for now | 26 | // FIXME: do nothing for now |
31 | Ok(Subtree::default()) | 27 | Ok(Subtree::default()) |
32 | } | 28 | } |
33 | } | 29 | } |
34 | 30 | ||
35 | #[derive(Debug, Clone)] | ||
36 | pub struct ProcMacro { | ||
37 | expander: Arc<dyn ProcMacroExpander>, | ||
38 | name: String, | ||
39 | } | ||
40 | |||
41 | impl Eq for ProcMacro {} | ||
42 | impl PartialEq for ProcMacro { | ||
43 | fn eq(&self, other: &ProcMacro) -> bool { | ||
44 | self.name == other.name && Arc::ptr_eq(&self.expander, &other.expander) | ||
45 | } | ||
46 | } | ||
47 | |||
48 | impl ProcMacro { | ||
49 | pub fn name(&self) -> String { | ||
50 | self.name.clone() | ||
51 | } | ||
52 | |||
53 | pub fn custom_derive(&self, subtree: &Subtree) -> Result<Subtree, ExpandError> { | ||
54 | self.expander.custom_derive(subtree, &self.name) | ||
55 | } | ||
56 | } | ||
57 | |||
58 | #[derive(Debug, Clone, PartialEq, Eq)] | 31 | #[derive(Debug, Clone, PartialEq, Eq)] |
59 | pub struct ProcMacroProcessSrv { | 32 | pub struct ProcMacroProcessSrv { |
60 | path: PathBuf, | 33 | path: PathBuf, |
@@ -76,7 +49,10 @@ impl ProcMacroClient { | |||
76 | ProcMacroClient::Dummy | 49 | ProcMacroClient::Dummy |
77 | } | 50 | } |
78 | 51 | ||
79 | pub fn by_dylib_path(&self, _dylib_path: &Path) -> Vec<ProcMacro> { | 52 | pub fn by_dylib_path( |
53 | &self, | ||
54 | _dylib_path: &Path, | ||
55 | ) -> Vec<(SmolStr, Arc<dyn ra_tt::TokenExpander>)> { | ||
80 | // FIXME: return empty for now | 56 | // FIXME: return empty for now |
81 | vec![] | 57 | vec![] |
82 | } | 58 | } |