From ae49a22b5cdd47add478fef6bb8ad3d75338e313 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Mon, 18 Nov 2019 03:35:46 +0800 Subject: Rebase --- crates/ra_hir/src/source_binder.rs | 5 +++++ crates/ra_ide_api/src/expand_macro.rs | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index f0ed8e2b2..6d75296a5 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -140,6 +140,11 @@ impl Expansion { exp_info.map_token_down(token) } + pub fn source(&self, db: &impl HirDatabase) -> Source> { + let loc = db.lookup_intern_macro(self.macro_call_id); + Source::new(self.file_id(), loc.ast_id) + } + fn file_id(&self) -> HirFileId { self.macro_call_id.as_file(MacroFileKind::Items) } diff --git a/crates/ra_ide_api/src/expand_macro.rs b/crates/ra_ide_api/src/expand_macro.rs index 48dc90932..49c096ed5 100644 --- a/crates/ra_ide_api/src/expand_macro.rs +++ b/crates/ra_ide_api/src/expand_macro.rs @@ -1,10 +1,10 @@ //! FIXME: write short doc here use crate::{db::RootDatabase, FilePosition}; +use hir::db::AstDatabase; use ra_db::SourceDatabase; use rustc_hash::FxHashMap; -use hir::db::AstDatabase; use ra_syntax::{ algo::{find_node_at_offset, replace_descendants}, ast::{self}, @@ -47,13 +47,14 @@ fn expand_macro_recur( ) -> Option { let analyzer = hir::SourceAnalyzer::new(db, source, None); let expansion = analyzer.expand(db, ¯o_call)?; - let expanded: SyntaxNode = db.parse_or_expand(expansion.file_id())?; + let new_source = expansion.source(db); + let expanded: SyntaxNode = db.parse_or_expand(new_source.file_id)?; let children = expanded.descendants().filter_map(ast::MacroCall::cast); let mut replaces = FxHashMap::default(); for child in children.into_iter() { - let source = hir::Source::new(expansion.file_id(), source.ast); + let source = new_source.with_ast(source.ast); let new_node = expand_macro_recur(db, source, &child)?; replaces.insert(child.syntax().clone().into(), new_node.into()); -- cgit v1.2.3