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/yellow | |
parent | dccaa5e45e9baaa2d286353a7499a89af1669e42 (diff) |
make ancestors and descendants inherent
Diffstat (limited to 'crates/ra_syntax/src/yellow')
-rw-r--r-- | crates/ra_syntax/src/yellow/mod.rs | 9 | ||||
-rw-r--r-- | crates/ra_syntax/src/yellow/syntax_text.rs | 4 |
2 files changed, 11 insertions, 2 deletions
diff --git a/crates/ra_syntax/src/yellow/mod.rs b/crates/ra_syntax/src/yellow/mod.rs index 2c57d8b41..95d277a2f 100644 --- a/crates/ra_syntax/src/yellow/mod.rs +++ b/crates/ra_syntax/src/yellow/mod.rs | |||
@@ -62,6 +62,15 @@ impl<'a> SyntaxNodeRef<'a> { | |||
62 | pub fn leaf_text(self) -> Option<&'a SmolStr> { | 62 | pub fn leaf_text(self) -> Option<&'a SmolStr> { |
63 | self.0.leaf_text() | 63 | self.0.leaf_text() |
64 | } | 64 | } |
65 | pub fn ancestors(self) -> impl Iterator<Item=SyntaxNodeRef<'a>> { | ||
66 | ::algo::generate(Some(self), |&node| node.parent()) | ||
67 | } | ||
68 | pub fn descendants(self) -> impl Iterator<Item=SyntaxNodeRef<'a>> { | ||
69 | ::algo::walk::walk(self).filter_map(|event| match event { | ||
70 | ::algo::walk::WalkEvent::Enter(node) => Some(node), | ||
71 | ::algo::walk::WalkEvent::Exit(_) => None, | ||
72 | }) | ||
73 | } | ||
65 | } | 74 | } |
66 | 75 | ||
67 | impl<R: TreeRoot<RaTypes>> SyntaxNode<R> { | 76 | impl<R: TreeRoot<RaTypes>> SyntaxNode<R> { |
diff --git a/crates/ra_syntax/src/yellow/syntax_text.rs b/crates/ra_syntax/src/yellow/syntax_text.rs index affd7f9c7..0db1049de 100644 --- a/crates/ra_syntax/src/yellow/syntax_text.rs +++ b/crates/ra_syntax/src/yellow/syntax_text.rs | |||
@@ -4,7 +4,6 @@ use std::{ | |||
4 | 4 | ||
5 | use { | 5 | use { |
6 | SyntaxNodeRef, TextRange, TextUnit, | 6 | SyntaxNodeRef, TextRange, TextUnit, |
7 | algo::walk::preorder, | ||
8 | text_utils::{intersect, contains_offset_nonstrict}, | 7 | text_utils::{intersect, contains_offset_nonstrict}, |
9 | }; | 8 | }; |
10 | 9 | ||
@@ -23,7 +22,8 @@ impl<'a> SyntaxText<'a> { | |||
23 | } | 22 | } |
24 | pub fn chunks(&self) -> impl Iterator<Item=&'a str> { | 23 | pub fn chunks(&self) -> impl Iterator<Item=&'a str> { |
25 | let range = self.range; | 24 | let range = self.range; |
26 | preorder(self.node) | 25 | self.node |
26 | .descendants() | ||
27 | .filter_map(move |node| { | 27 | .filter_map(move |node| { |
28 | let text = node.leaf_text()?; | 28 | let text = node.leaf_text()?; |
29 | let range = intersect(range, node.range())?; | 29 | let range = intersect(range, node.range())?; |