mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-18 08:10:11 +00:00
make ancestors and descendants inherent
This commit is contained in:
parent
dccaa5e45e
commit
d323c81d5c
14 changed files with 40 additions and 46 deletions
|
@ -94,10 +94,6 @@ pub fn find_covering_node(root: SyntaxNodeRef, range: TextRange) -> SyntaxNodeRe
|
|||
common_ancestor(left, right)
|
||||
}
|
||||
|
||||
pub fn ancestors<'a>(node: SyntaxNodeRef<'a>) -> impl Iterator<Item=SyntaxNodeRef<'a>> {
|
||||
generate(Some(node), |&node| node.parent())
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Direction {
|
||||
Forward,
|
||||
|
@ -115,8 +111,8 @@ pub fn siblings<'a>(
|
|||
}
|
||||
|
||||
fn common_ancestor<'a>(n1: SyntaxNodeRef<'a>, n2: SyntaxNodeRef<'a>) -> SyntaxNodeRef<'a> {
|
||||
for p in ancestors(n1) {
|
||||
if ancestors(n2).any(|a| a == p) {
|
||||
for p in n1.ancestors() {
|
||||
if n2.ancestors().any(|a| a == p) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,12 +3,6 @@ use {
|
|||
algo::generate,
|
||||
};
|
||||
|
||||
pub fn preorder<'a>(root: SyntaxNodeRef<'a>) -> impl Iterator<Item = SyntaxNodeRef<'a>> {
|
||||
walk(root).filter_map(|event| match event {
|
||||
WalkEvent::Enter(node) => Some(node),
|
||||
WalkEvent::Exit(_) => None,
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum WalkEvent<'a> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue