From caa8663c08e1724af2abcde11fa937937d76aa14 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 14 May 2019 01:52:31 +0300 Subject: allow expanding expressions --- crates/ra_hir/src/expr.rs | 11 ++++------- crates/ra_hir/src/ids.rs | 4 ++++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index 288f85b01..9618236e5 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs @@ -830,14 +830,11 @@ where if let Some(def) = self.resolver.resolve_macro_call(path) { let call_id = MacroCallLoc { def, ast_id }.id(self.db); - if let Some(tt) = self.db.macro_expand(call_id).ok() { - if let Some(expr) = mbe::token_tree_to_expr(&tt).ok() { + let file_id = call_id.as_file(MacroFileKind::Expr); + if let Some(node) = self.db.parse_or_expand(file_id) { + if let Some(expr) = ast::Expr::cast(&*node) { log::debug!("macro expansion {}", expr.syntax().debug_dump()); - let old_file_id = std::mem::replace( - &mut self.current_file_id, - //BUG - call_id.as_file(MacroFileKind::Items), - ); + let old_file_id = std::mem::replace(&mut self.current_file_id, file_id); let id = self.collect_expr(&expr); self.current_file_id = old_file_id; return id; diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index 659b21f72..f901a7432 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs @@ -81,6 +81,9 @@ impl HirFileId { MacroFileKind::Items => { Some(mbe::token_tree_to_ast_item_list(&tt).syntax().to_owned()) } + MacroFileKind::Expr => { + mbe::token_tree_to_expr(&tt).ok().map(|it| it.syntax().to_owned()) + } } } } @@ -102,6 +105,7 @@ struct MacroFile { #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub(crate) enum MacroFileKind { Items, + Expr, } impl From for HirFileId { -- cgit v1.2.3