aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/expand_macro.rs
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2021-06-08 21:13:22 +0100
committerJonas Schievink <[email protected]>2021-06-08 21:26:01 +0100
commitfcf22d68d45f1668dfca95d20d609dceb32eded5 (patch)
tree399bb0ae22046862c20bf0c4e32aaf08ddfaab2d /crates/ide/src/expand_macro.rs
parentb6199de706868dcbf57d9821829381609212d851 (diff)
Prefer attr macros in "expand macro recursively"
Diffstat (limited to 'crates/ide/src/expand_macro.rs')
-rw-r--r--crates/ide/src/expand_macro.rs34
1 files changed, 14 insertions, 20 deletions
diff --git a/crates/ide/src/expand_macro.rs b/crates/ide/src/expand_macro.rs
index 3f38e2145..cc43c5772 100644
--- a/crates/ide/src/expand_macro.rs
+++ b/crates/ide/src/expand_macro.rs
@@ -2,9 +2,7 @@ use std::iter;
2 2
3use hir::Semantics; 3use hir::Semantics;
4use ide_db::RootDatabase; 4use ide_db::RootDatabase;
5use syntax::{ 5use syntax::{ast, ted, AstNode, NodeOrToken, SyntaxKind, SyntaxKind::*, SyntaxNode, WalkEvent, T};
6 ast, match_ast, ted, AstNode, NodeOrToken, SyntaxKind, SyntaxKind::*, SyntaxNode, WalkEvent, T,
7};
8 6
9use crate::FilePosition; 7use crate::FilePosition;
10 8
@@ -32,25 +30,21 @@ pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option<
32 let mut expanded = None; 30 let mut expanded = None;
33 let mut name = None; 31 let mut name = None;
34 for node in tok.ancestors() { 32 for node in tok.ancestors() {
35 match_ast! { 33 if let Some(item) = ast::Item::cast(node.clone()) {
36 match node { 34 expanded = sema.expand_attr_macro(&item);
37 ast::MacroCall(mac) => { 35 if expanded.is_some() {
38 name = Some(mac.path()?.segment()?.name_ref()?.to_string()); 36 // FIXME: add the macro name
39 expanded = expand_macro_recur(&sema, &mac); 37 // FIXME: make this recursive too
40 break; 38 name = Some("?".to_string());
41 }, 39 break;
42 ast::Item(item) => {
43 // FIXME: add the macro name
44 // FIXME: make this recursive too
45 name = Some("?".to_string());
46 expanded = sema.expand_attr_macro(&item);
47 if expanded.is_some() {
48 break;
49 }
50 },
51 _ => {}
52 } 40 }
53 } 41 }
42
43 if let Some(mac) = ast::MacroCall::cast(node) {
44 name = Some(mac.path()?.segment()?.name_ref()?.to_string());
45 expanded = expand_macro_recur(&sema, &mac);
46 break;
47 }
54 } 48 }
55 49
56 // FIXME: 50 // FIXME: