aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2019-11-23 02:33:14 +0000
committerEdwin Cheng <[email protected]>2019-11-23 02:33:14 +0000
commit9c521f00ff118c38cbec730ffae1cee5f465f6ac (patch)
tree9e2a135b29fff2ad6ec496cc3a9f5e169c757827 /crates/ra_ide_api
parent5b19202e00fffe62a1a9c07f4b974f0affdd0c66 (diff)
Improve fail case in expand_macro
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r--crates/ra_ide_api/src/expand_macro.rs40
1 files changed, 31 insertions, 9 deletions
diff --git a/crates/ra_ide_api/src/expand_macro.rs b/crates/ra_ide_api/src/expand_macro.rs
index 673301b10..0b540b8cd 100644
--- a/crates/ra_ide_api/src/expand_macro.rs
+++ b/crates/ra_ide_api/src/expand_macro.rs
@@ -47,15 +47,15 @@ fn expand_macro_recur(
47 47
48 for child in children.into_iter() { 48 for child in children.into_iter() {
49 let node = hir::Source::new(macro_file_id, &child); 49 let node = hir::Source::new(macro_file_id, &child);
50 let new_node = expand_macro_recur(db, source, node)?; 50 if let Some(new_node) = expand_macro_recur(db, source, node) {
51 51 // Replace the whole node if it is root
52 // Replace the whole node if it is root 52 // `replace_descendants` will not replace the parent node
53 // `replace_descendants` will not replace the parent node 53 // but `SyntaxNode::descendants include itself
54 // but `SyntaxNode::descendants include itself 54 if expanded == *child.syntax() {
55 if expanded == *child.syntax() { 55 expanded = new_node;
56 expanded = new_node; 56 } else {
57 } else { 57 replaces.insert(child.syntax().clone().into(), new_node.into());
58 replaces.insert(child.syntax().clone().into(), new_node.into()); 58 }
59 } 59 }
60 } 60 }
61 61
@@ -247,4 +247,26 @@ fn some_thing() -> u32 {
247 assert_eq!(res.name, "match_ast"); 247 assert_eq!(res.name, "match_ast");
248 assert_snapshot!(res.expansion, @r###"{}"###); 248 assert_snapshot!(res.expansion, @r###"{}"###);
249 } 249 }
250
251 #[test]
252 fn macro_expand_inner_macro_fail_to_expand() {
253 let res = check_expand_macro(
254 r#"
255 //- /lib.rs
256 macro_rules! bar {
257 (BAD) => {};
258 }
259 macro_rules! foo {
260 () => {bar!()};
261 }
262
263 fn main() {
264 let res = fo<|>o!();
265 }
266 "#,
267 );
268
269 assert_eq!(res.name, "foo");
270 assert_snapshot!(res.expansion, @r###"bar!()"###);
271 }
250} 272}