mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-18 16:20:18 +00:00
Make siblings an inherent method
This commit is contained in:
parent
d323c81d5c
commit
1a2a8dec14
6 changed files with 30 additions and 34 deletions
|
@ -94,22 +94,6 @@ pub fn find_covering_node(root: SyntaxNodeRef, range: TextRange) -> SyntaxNodeRe
|
|||
common_ancestor(left, right)
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Direction {
|
||||
Forward,
|
||||
Backward,
|
||||
}
|
||||
|
||||
pub fn siblings<'a>(
|
||||
node: SyntaxNodeRef<'a>,
|
||||
direction: Direction
|
||||
) -> impl Iterator<Item=SyntaxNodeRef<'a>> {
|
||||
generate(Some(node), move |&node| match direction {
|
||||
Direction::Forward => node.next_sibling(),
|
||||
Direction::Backward => node.prev_sibling(),
|
||||
})
|
||||
}
|
||||
|
||||
fn common_ancestor<'a>(n1: SyntaxNodeRef<'a>, n2: SyntaxNodeRef<'a>) -> SyntaxNodeRef<'a> {
|
||||
for p in n1.ancestors() {
|
||||
if n2.ancestors().any(|a| a == p) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue