From 101b3abfd70cc988b24f30a610d46a3986df54d3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 14 May 2019 01:12:07 +0300 Subject: store macro kind in HirFileId --- crates/ra_hir/src/expr.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'crates/ra_hir/src/expr.rs') diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index a2b5db1a1..288f85b01 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs @@ -6,11 +6,11 @@ use rustc_hash::FxHashMap; use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap}; use ra_syntax::{ SyntaxNodePtr, AstPtr, AstNode, - ast::{self, LoopBodyOwner, ArgListOwner, NameOwner, LiteralKind,ArrayExprKind, TypeAscriptionOwner} + ast::{self, LoopBodyOwner, ArgListOwner, NameOwner, LiteralKind,ArrayExprKind, TypeAscriptionOwner}, }; use crate::{ - Path, Name, HirDatabase, Resolver,DefWithBody, Either, HirFileId, MacroCallLoc, + Path, Name, HirDatabase, Resolver,DefWithBody, Either, HirFileId, MacroCallLoc, MacroFileKind, name::AsName, type_ref::{Mutability, TypeRef}, }; @@ -833,8 +833,11 @@ where if let Some(tt) = self.db.macro_expand(call_id).ok() { if let Some(expr) = mbe::token_tree_to_expr(&tt).ok() { log::debug!("macro expansion {}", expr.syntax().debug_dump()); - let old_file_id = - std::mem::replace(&mut self.current_file_id, call_id.into()); + let old_file_id = std::mem::replace( + &mut self.current_file_id, + //BUG + call_id.as_file(MacroFileKind::Items), + ); let id = self.collect_expr(&expr); self.current_file_id = old_file_id; return id; -- cgit v1.2.3 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 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'crates/ra_hir/src/expr.rs') 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; -- cgit v1.2.3