mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Prefer attr macros in "expand macro recursively"
This commit is contained in:
parent
b6199de706
commit
fcf22d68d4
1 changed files with 14 additions and 20 deletions
|
@ -2,9 +2,7 @@ use std::iter;
|
|||
|
||||
use hir::Semantics;
|
||||
use ide_db::RootDatabase;
|
||||
use syntax::{
|
||||
ast, match_ast, ted, AstNode, NodeOrToken, SyntaxKind, SyntaxKind::*, SyntaxNode, WalkEvent, T,
|
||||
};
|
||||
use syntax::{ast, ted, AstNode, NodeOrToken, SyntaxKind, SyntaxKind::*, SyntaxNode, WalkEvent, T};
|
||||
|
||||
use crate::FilePosition;
|
||||
|
||||
|
@ -32,24 +30,20 @@ pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option<
|
|||
let mut expanded = None;
|
||||
let mut name = None;
|
||||
for node in tok.ancestors() {
|
||||
match_ast! {
|
||||
match node {
|
||||
ast::MacroCall(mac) => {
|
||||
name = Some(mac.path()?.segment()?.name_ref()?.to_string());
|
||||
expanded = expand_macro_recur(&sema, &mac);
|
||||
break;
|
||||
},
|
||||
ast::Item(item) => {
|
||||
if let Some(item) = ast::Item::cast(node.clone()) {
|
||||
expanded = sema.expand_attr_macro(&item);
|
||||
if expanded.is_some() {
|
||||
// FIXME: add the macro name
|
||||
// FIXME: make this recursive too
|
||||
name = Some("?".to_string());
|
||||
expanded = sema.expand_attr_macro(&item);
|
||||
if expanded.is_some() {
|
||||
break;
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
|
||||
if let Some(mac) = ast::MacroCall::cast(node) {
|
||||
name = Some(mac.path()?.segment()?.name_ref()?.to_string());
|
||||
expanded = expand_macro_recur(&sema, &mac);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue