aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_proc_macro/src
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2020-03-26 16:41:44 +0000
committerEdwin Cheng <[email protected]>2020-03-26 16:46:40 +0000
commitdb162df264a222021dbc7f1f93af94029f3948d9 (patch)
tree86f91e30f85c2c4f5faa5054b84265ddb64636d5 /crates/ra_proc_macro/src
parent72e68d0caf6e813a19a8d434fb650574b73dbc0a (diff)
Remove deps on tt_mbe
Diffstat (limited to 'crates/ra_proc_macro/src')
-rw-r--r--crates/ra_proc_macro/src/lib.rs44
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
8use ra_mbe::ExpandError; 8use ra_tt::{SmolStr, Subtree};
9use ra_tt::Subtree;
10use std::{ 9use std::{
11 path::{Path, PathBuf}, 10 path::{Path, PathBuf},
12 sync::Arc, 11 sync::Arc,
13}; 12};
14 13
15trait 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)]
20pub struct ProcMacroProcessExpander { 15pub struct ProcMacroProcessExpander {
21 process: Arc<ProcMacroProcessSrv>, 16 process: Arc<ProcMacroProcessSrv>,
17 name: SmolStr,
22} 18}
23 19
24impl ProcMacroExpander for ProcMacroProcessExpander { 20impl 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)]
36pub struct ProcMacro {
37 expander: Arc<dyn ProcMacroExpander>,
38 name: String,
39}
40
41impl Eq for ProcMacro {}
42impl 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
48impl 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)]
59pub struct ProcMacroProcessSrv { 32pub 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 }