aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/expand_macro.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/expand_macro.rs')
-rw-r--r--crates/ra_ide_api/src/expand_macro.rs16
1 files changed, 8 insertions, 8 deletions
diff --git a/crates/ra_ide_api/src/expand_macro.rs b/crates/ra_ide_api/src/expand_macro.rs
index e9eb2a7fb..7f39262dc 100644
--- a/crates/ra_ide_api/src/expand_macro.rs
+++ b/crates/ra_ide_api/src/expand_macro.rs
@@ -23,7 +23,7 @@ pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option<
23 let mac = name_ref.syntax().ancestors().find_map(ast::MacroCall::cast)?; 23 let mac = name_ref.syntax().ancestors().find_map(ast::MacroCall::cast)?;
24 24
25 let source = hir::Source::new(position.file_id.into(), mac.syntax()); 25 let source = hir::Source::new(position.file_id.into(), mac.syntax());
26 let expanded = expand_macro_recur(db, source, &mac)?; 26 let expanded = expand_macro_recur(db, source, source.with_value(&mac))?;
27 27
28 // FIXME: 28 // FIXME:
29 // macro expansion may lose all white space information 29 // macro expansion may lose all white space information
@@ -35,10 +35,10 @@ pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option<
35fn expand_macro_recur( 35fn expand_macro_recur(
36 db: &RootDatabase, 36 db: &RootDatabase,
37 source: hir::Source<&SyntaxNode>, 37 source: hir::Source<&SyntaxNode>,
38 macro_call: &ast::MacroCall, 38 macro_call: hir::Source<&ast::MacroCall>,
39) -> Option<SyntaxNode> { 39) -> Option<SyntaxNode> {
40 let analyzer = hir::SourceAnalyzer::new(db, source, None); 40 let analyzer = hir::SourceAnalyzer::new(db, source, None);
41 let expansion = analyzer.expand(db, &macro_call)?; 41 let expansion = analyzer.expand(db, macro_call)?;
42 let macro_file_id = expansion.file_id(); 42 let macro_file_id = expansion.file_id();
43 let expanded: SyntaxNode = db.parse_or_expand(macro_file_id)?; 43 let expanded: SyntaxNode = db.parse_or_expand(macro_file_id)?;
44 44
@@ -46,8 +46,8 @@ fn expand_macro_recur(
46 let mut replaces = FxHashMap::default(); 46 let mut replaces = FxHashMap::default();
47 47
48 for child in children.into_iter() { 48 for child in children.into_iter() {
49 let source = hir::Source::new(macro_file_id, source.ast); 49 let node = hir::Source::new(macro_file_id, &child);
50 let new_node = expand_macro_recur(db, source, &child)?; 50 let new_node = expand_macro_recur(db, source, node)?;
51 51
52 replaces.insert(child.syntax().clone().into(), new_node.into()); 52 replaces.insert(child.syntax().clone().into(), new_node.into());
53 } 53 }
@@ -139,7 +139,7 @@ mod tests {
139 } 139 }
140 macro_rules! baz { 140 macro_rules! baz {
141 () => { foo!(); } 141 () => { foo!(); }
142 } 142 }
143 f<|>oo!(); 143 f<|>oo!();
144 "#, 144 "#,
145 ); 145 );
@@ -156,7 +156,7 @@ fn b(){}
156 r#" 156 r#"
157 //- /lib.rs 157 //- /lib.rs
158 macro_rules! foo { 158 macro_rules! foo {
159 () => { 159 () => {
160 fn some_thing() -> u32 { 160 fn some_thing() -> u32 {
161 let a = 0; 161 let a = 0;
162 a + 10 162 a + 10
@@ -172,7 +172,7 @@ fn b(){}
172fn some_thing() -> u32 { 172fn some_thing() -> u32 {
173 let a = 0; 173 let a = 0;
174 a+10 174 a+10
175} 175}
176"###); 176"###);
177 } 177 }
178} 178}