aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_expand/src
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2020-03-18 12:56:46 +0000
committerEdwin Cheng <[email protected]>2020-03-25 19:29:45 +0000
commitd0b6ed4441469acfb6bc6555d78abf12637b6cf4 (patch)
treea4b39b33590c472a68fd76ceae96732e9cb54ebb /crates/ra_hir_expand/src
parenta617f24eae6c02f087759312e9aa08507fbecdf0 (diff)
Add ProcMacroClient
Diffstat (limited to 'crates/ra_hir_expand/src')
-rw-r--r--crates/ra_hir_expand/src/proc_macro.rs30
1 files changed, 14 insertions, 16 deletions
diff --git a/crates/ra_hir_expand/src/proc_macro.rs b/crates/ra_hir_expand/src/proc_macro.rs
index a8dee2052..296325b05 100644
--- a/crates/ra_hir_expand/src/proc_macro.rs
+++ b/crates/ra_hir_expand/src/proc_macro.rs
@@ -1,33 +1,31 @@
1//! Proc Macro Expander stub 1//! Proc Macro Expander stub
2 2
3use crate::{db::AstDatabase, LazyMacroId, MacroCallKind, MacroCallLoc}; 3use crate::{db::AstDatabase, LazyMacroId};
4use ra_db::CrateId; 4use ra_db::{CrateId, ProcMacroId};
5 5
6#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)] 6#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
7pub struct ProcMacroExpander { 7pub struct ProcMacroExpander {
8 krate: CrateId, 8 krate: CrateId,
9 proc_macro_id: ProcMacroId,
9} 10}
10 11
11impl ProcMacroExpander { 12impl ProcMacroExpander {
12 pub fn new(krate: CrateId) -> ProcMacroExpander { 13 pub fn new(krate: CrateId, proc_macro_id: ProcMacroId) -> ProcMacroExpander {
13 ProcMacroExpander { krate } 14 ProcMacroExpander { krate, proc_macro_id }
14 } 15 }
15 16
16 pub fn expand( 17 pub fn expand(
17 &self, 18 &self,
18 db: &dyn AstDatabase, 19 db: &dyn AstDatabase,
19 id: LazyMacroId, 20 _id: LazyMacroId,
20 _tt: &tt::Subtree, 21 tt: &tt::Subtree,
21 ) -> Result<tt::Subtree, mbe::ExpandError> { 22 ) -> Result<tt::Subtree, mbe::ExpandError> {
22 let loc: MacroCallLoc = db.lookup_intern_macro(id); 23 let krate_graph = db.crate_graph();
23 let name = match loc.kind { 24 let proc_macro = krate_graph[self.krate]
24 MacroCallKind::FnLike(_) => return Err(mbe::ExpandError::ConversionError), 25 .proc_macro
25 MacroCallKind::Attr(_, name) => name, 26 .get(self.proc_macro_id.0)
26 }; 27 .clone()
27 28 .ok_or_else(|| mbe::ExpandError::ConversionError)?;
28 log::debug!("Proc-macro-expanding name = {}", name); 29 proc_macro.custom_derive(tt)
29
30 // Return nothing for now
31 return Ok(tt::Subtree::default());
32 } 30 }
33} 31}