mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
Implement ancestors_with_macros in a better way
This commit is contained in:
parent
c80dc0ad3a
commit
b2c01f446e
2 changed files with 22 additions and 12 deletions
|
@ -76,7 +76,7 @@ fn def_with_body_from_child_node(
|
|||
db: &impl HirDatabase,
|
||||
child: InFile<&SyntaxNode>,
|
||||
) -> Option<DefWithBody> {
|
||||
ancestors_with_macros(db, child).find_map(|node| {
|
||||
child.cloned().ancestors_with_macros(db).find_map(|node| {
|
||||
let n = &node.value;
|
||||
match_ast! {
|
||||
match n {
|
||||
|
@ -89,17 +89,6 @@ fn def_with_body_from_child_node(
|
|||
})
|
||||
}
|
||||
|
||||
fn ancestors_with_macros<'a>(
|
||||
db: &'a (impl HirDatabase),
|
||||
node: InFile<&SyntaxNode>,
|
||||
) -> impl Iterator<Item = InFile<SyntaxNode>> + 'a {
|
||||
let file = node.with_value(()); // keep just the file id for borrow checker purposes
|
||||
let parent_node = node.file_id.call_node(db);
|
||||
let parent_ancestors: Box<dyn Iterator<Item = InFile<SyntaxNode>>> =
|
||||
Box::new(parent_node.into_iter().flat_map(move |n| ancestors_with_macros(db, n.as_ref())));
|
||||
node.value.ancestors().map(move |n| file.with_value(n)).chain(parent_ancestors)
|
||||
}
|
||||
|
||||
/// `SourceAnalyzer` is a convenience wrapper which exposes HIR API in terms of
|
||||
/// original source files. It should not be used inside the HIR itself.
|
||||
#[derive(Debug)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue