diff options
author | Edwin Cheng <[email protected]> | 2019-11-17 19:35:46 +0000 |
---|---|---|
committer | Edwin Cheng <[email protected]> | 2019-11-19 13:49:06 +0000 |
commit | ae49a22b5cdd47add478fef6bb8ad3d75338e313 (patch) | |
tree | 2ac2304eb3cafca527b8a6d817bd37186b3fe89a /crates | |
parent | 3ccd05fedc46796f793295901a8619492256468e (diff) |
Rebase
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 5 | ||||
-rw-r--r-- | 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 { | |||
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 | ||
3 | use crate::{db::RootDatabase, FilePosition}; | 3 | use crate::{db::RootDatabase, FilePosition}; |
4 | use hir::db::AstDatabase; | ||
4 | use ra_db::SourceDatabase; | 5 | use ra_db::SourceDatabase; |
5 | use rustc_hash::FxHashMap; | 6 | use rustc_hash::FxHashMap; |
6 | 7 | ||
7 | use hir::db::AstDatabase; | ||
8 | use ra_syntax::{ | 8 | use 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, ¯o_call)?; | 49 | let expansion = analyzer.expand(db, ¯o_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()); |