diff options
author | Aleksey Kladov <[email protected]> | 2018-10-02 16:02:57 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-10-02 16:02:57 +0100 |
commit | d323c81d5cc6a198239285abcede2166181d8f39 (patch) | |
tree | 02c64a01b14d893df439a9e90797db6d58c5a54d /crates/ra_syntax/src/algo/mod.rs | |
parent | dccaa5e45e9baaa2d286353a7499a89af1669e42 (diff) |
make ancestors and descendants inherent
Diffstat (limited to 'crates/ra_syntax/src/algo/mod.rs')
-rw-r--r-- | crates/ra_syntax/src/algo/mod.rs | 8 |
1 files changed, 2 insertions, 6 deletions
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 | |||
94 | common_ancestor(left, right) | 94 | common_ancestor(left, right) |
95 | } | 95 | } |
96 | 96 | ||
97 | pub fn ancestors<'a>(node: SyntaxNodeRef<'a>) -> impl Iterator<Item=SyntaxNodeRef<'a>> { | ||
98 | generate(Some(node), |&node| node.parent()) | ||
99 | } | ||
100 | |||
101 | #[derive(Debug)] | 97 | #[derive(Debug)] |
102 | pub enum Direction { | 98 | pub enum Direction { |
103 | Forward, | 99 | Forward, |
@@ -115,8 +111,8 @@ pub fn siblings<'a>( | |||
115 | } | 111 | } |
116 | 112 | ||
117 | fn common_ancestor<'a>(n1: SyntaxNodeRef<'a>, n2: SyntaxNodeRef<'a>) -> SyntaxNodeRef<'a> { | 113 | fn common_ancestor<'a>(n1: SyntaxNodeRef<'a>, n2: SyntaxNodeRef<'a>) -> SyntaxNodeRef<'a> { |
118 | for p in ancestors(n1) { | 114 | for p in n1.ancestors() { |
119 | if ancestors(n2).any(|a| a == p) { | 115 | if n2.ancestors().any(|a| a == p) { |
120 | return p; | 116 | return p; |
121 | } | 117 | } |
122 | } | 118 | } |