From d323c81d5cc6a198239285abcede2166181d8f39 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 2 Oct 2018 18:02:57 +0300 Subject: make ancestors and descendants inherent --- crates/ra_syntax/src/algo/mod.rs | 8 ++------ crates/ra_syntax/src/algo/walk.rs | 6 ------ 2 files changed, 2 insertions(+), 12 deletions(-) (limited to 'crates/ra_syntax/src/algo') diff --git a/crates/ra_syntax/src/algo/mod.rs b/crates/ra_syntax/src/algo/mod.rs index 8de44c586..3716a6000 100644 --- a/crates/ra_syntax/src/algo/mod.rs +++ b/crates/ra_syntax/src/algo/mod.rs @@ -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> { - 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; } } diff --git a/crates/ra_syntax/src/algo/walk.rs b/crates/ra_syntax/src/algo/walk.rs index 536ee705f..8e294d965 100644 --- a/crates/ra_syntax/src/algo/walk.rs +++ b/crates/ra_syntax/src/algo/walk.rs @@ -3,12 +3,6 @@ use { algo::generate, }; -pub fn preorder<'a>(root: SyntaxNodeRef<'a>) -> impl Iterator> { - walk(root).filter_map(|event| match event { - WalkEvent::Enter(node) => Some(node), - WalkEvent::Exit(_) => None, - }) -} #[derive(Debug, Copy, Clone)] pub enum WalkEvent<'a> { -- cgit v1.2.3 From 1a2a8dec14ec04ea8eeccae99fd885e7a280e45b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 2 Oct 2018 18:14:33 +0300 Subject: Make siblings an inherent method --- crates/ra_syntax/src/algo/mod.rs | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'crates/ra_syntax/src/algo') diff --git a/crates/ra_syntax/src/algo/mod.rs b/crates/ra_syntax/src/algo/mod.rs index 3716a6000..a6678093d 100644 --- a/crates/ra_syntax/src/algo/mod.rs +++ b/crates/ra_syntax/src/algo/mod.rs @@ -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> { - 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) { -- cgit v1.2.3