aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_expand/src/proc_macro.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-03-26 17:09:32 +0000
committerGitHub <[email protected]>2020-03-26 17:09:32 +0000
commitb1594f108041813c9fa32538950c15c55202cbd5 (patch)
treecef1e662a7acf2807422e7c232014c5326ac37b6 /crates/ra_hir_expand/src/proc_macro.rs
parent20c110e57f24aa54154942ee40921e9129fbc595 (diff)
parentdb162df264a222021dbc7f1f93af94029f3948d9 (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_hir_expand/src/proc_macro.rs')
-rw-r--r--crates/ra_hir_expand/src/proc_macro.rs29
1 files changed, 14 insertions, 15 deletions
diff --git a/crates/ra_hir_expand/src/proc_macro.rs b/crates/ra_hir_expand/src/proc_macro.rs
index a8dee2052..4d270e0de 100644
--- a/crates/ra_hir_expand/src/proc_macro.rs
+++ b/crates/ra_hir_expand/src/proc_macro.rs
@@ -1,33 +1,32 @@
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 as usize)
26 }; 27 .clone()
28 .ok_or_else(|| mbe::ExpandError::ConversionError)?;
27 29
28 log::debug!("Proc-macro-expanding name = {}", name); 30 proc_macro.expander.expand(&tt, None).map_err(mbe::ExpandError::from)
29
30 // Return nothing for now
31 return Ok(tt::Subtree::default());
32 } 31 }
33} 32}