aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-06-08 22:08:58 +0100
committerGitHub <[email protected]>2021-06-08 22:08:58 +0100
commitcc7cfc5d3d7777524a9e8a94da3f5f2dd455fc0a (patch)
tree371a9118ee00132a090d87b438a31fa813526735
parenta60978d172c6985c071dd0d9f28caa5fa5364a3e (diff)
parentfcf22d68d45f1668dfca95d20d609dceb32eded5 (diff)
Merge #9186
9186: fix: Prefer attr macros in "expand macro recursively" r=jonas-schievink a=jonas-schievink This allows expanding attribute macros on fn-like macro invocations bors r+ Co-authored-by: Jonas Schievink <[email protected]>
-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: