aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir/src/source_binder.rs5
-rw-r--r--crates/ra_ide_api/src/expand_macro.rs7
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 {
140 exp_info.map_token_down(token) 140 exp_info.map_token_down(token)
141 } 141 }
142 142
143 pub fn source(&self, db: &impl HirDatabase) -> Source<AstId<ast::MacroCall>> {
144 let loc = db.lookup_intern_macro(self.macro_call_id);
145 Source::new(self.file_id(), loc.ast_id)
146 }
147
143 fn file_id(&self) -> HirFileId { 148 fn file_id(&self) -> HirFileId {
144 self.macro_call_id.as_file(MacroFileKind::Items) 149 self.macro_call_id.as_file(MacroFileKind::Items)
145 } 150 }
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 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use crate::{db::RootDatabase, FilePosition}; 3use crate::{db::RootDatabase, FilePosition};
4use hir::db::AstDatabase;
4use ra_db::SourceDatabase; 5use ra_db::SourceDatabase;
5use rustc_hash::FxHashMap; 6use rustc_hash::FxHashMap;
6 7
7use hir::db::AstDatabase;
8use ra_syntax::{ 8use ra_syntax::{
9 algo::{find_node_at_offset, replace_descendants}, 9 algo::{find_node_at_offset, replace_descendants},
10 ast::{self}, 10 ast::{self},
@@ -47,13 +47,14 @@ fn expand_macro_recur(
47) -> Option<SyntaxNode> { 47) -> Option<SyntaxNode> {
48 let analyzer = hir::SourceAnalyzer::new(db, source, None); 48 let analyzer = hir::SourceAnalyzer::new(db, source, None);
49 let expansion = analyzer.expand(db, &macro_call)?; 49 let expansion = analyzer.expand(db, &macro_call)?;
50 let expanded: SyntaxNode = db.parse_or_expand(expansion.file_id())?; 50 let new_source = expansion.source(db);
51 let expanded: SyntaxNode = db.parse_or_expand(new_source.file_id)?;
51 52
52 let children = expanded.descendants().filter_map(ast::MacroCall::cast); 53 let children = expanded.descendants().filter_map(ast::MacroCall::cast);
53 let mut replaces = FxHashMap::default(); 54 let mut replaces = FxHashMap::default();
54 55
55 for child in children.into_iter() { 56 for child in children.into_iter() {
56 let source = hir::Source::new(expansion.file_id(), source.ast); 57 let source = new_source.with_ast(source.ast);
57 let new_node = expand_macro_recur(db, source, &child)?; 58 let new_node = expand_macro_recur(db, source, &child)?;
58 59
59 replaces.insert(child.syntax().clone().into(), new_node.into()); 60 replaces.insert(child.syntax().clone().into(), new_node.into());