diff options
Diffstat (limited to 'crates/ra_hir_def/src/body.rs')
-rw-r--r-- | crates/ra_hir_def/src/body.rs | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs index afceeb8de..65fefd912 100644 --- a/crates/ra_hir_def/src/body.rs +++ b/crates/ra_hir_def/src/body.rs | |||
@@ -3,9 +3,12 @@ mod lower; | |||
3 | 3 | ||
4 | use std::{ops::Index, sync::Arc}; | 4 | use std::{ops::Index, sync::Arc}; |
5 | 5 | ||
6 | use hir_expand::{either::Either, hygiene::Hygiene, HirFileId, MacroDefId, Source}; | 6 | use hir_expand::{ |
7 | either::Either, hygiene::Hygiene, AstId, HirFileId, MacroCallLoc, MacroDefId, MacroFileKind, | ||
8 | Source, | ||
9 | }; | ||
7 | use ra_arena::{map::ArenaMap, Arena}; | 10 | use ra_arena::{map::ArenaMap, Arena}; |
8 | use ra_syntax::{ast, AstPtr}; | 11 | use ra_syntax::{ast, AstNode, AstPtr}; |
9 | use rustc_hash::FxHashMap; | 12 | use rustc_hash::FxHashMap; |
10 | 13 | ||
11 | use crate::{ | 14 | use crate::{ |
@@ -37,6 +40,35 @@ impl Expander { | |||
37 | } | 40 | } |
38 | } | 41 | } |
39 | 42 | ||
43 | fn expand( | ||
44 | &mut self, | ||
45 | db: &impl DefDatabase2, | ||
46 | macro_call: ast::MacroCall, | ||
47 | ) -> Option<(Mark, ast::Expr)> { | ||
48 | let ast_id = AstId::new( | ||
49 | self.current_file_id, | ||
50 | db.ast_id_map(self.current_file_id).ast_id(¯o_call), | ||
51 | ); | ||
52 | |||
53 | if let Some(path) = macro_call.path().and_then(|path| self.parse_path(path)) { | ||
54 | if let Some(def) = self.resolve_path_as_macro(db, &path) { | ||
55 | let call_id = db.intern_macro(MacroCallLoc { def, ast_id }); | ||
56 | let file_id = call_id.as_file(MacroFileKind::Expr); | ||
57 | if let Some(node) = db.parse_or_expand(file_id) { | ||
58 | if let Some(expr) = ast::Expr::cast(node) { | ||
59 | log::debug!("macro expansion {:#?}", expr.syntax()); | ||
60 | let mark = self.enter(db, file_id); | ||
61 | return Some((mark, expr)); | ||
62 | } | ||
63 | } | ||
64 | } | ||
65 | } | ||
66 | |||
67 | // FIXME: Instead of just dropping the error from expansion | ||
68 | // report it | ||
69 | None | ||
70 | } | ||
71 | |||
40 | fn enter(&mut self, db: &impl DefDatabase2, file_id: HirFileId) -> Mark { | 72 | fn enter(&mut self, db: &impl DefDatabase2, file_id: HirFileId) -> Mark { |
41 | let mark = Mark { file_id: self.current_file_id }; | 73 | let mark = Mark { file_id: self.current_file_id }; |
42 | self.hygiene = Hygiene::new(db, file_id); | 74 | self.hygiene = Hygiene::new(db, file_id); |