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