diff options
Diffstat (limited to 'crates/ra_syntax/src/yellow')
-rw-r--r-- | crates/ra_syntax/src/yellow/mod.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/yellow/mod.rs b/crates/ra_syntax/src/yellow/mod.rs index 95d277a2f..710320f47 100644 --- a/crates/ra_syntax/src/yellow/mod.rs +++ b/crates/ra_syntax/src/yellow/mod.rs | |||
@@ -58,6 +58,13 @@ impl SyntaxNode { | |||
58 | SyntaxNode(::rowan::SyntaxNode::new(green, errors)) | 58 | SyntaxNode(::rowan::SyntaxNode::new(green, errors)) |
59 | } | 59 | } |
60 | } | 60 | } |
61 | |||
62 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
63 | pub enum Direction { | ||
64 | Next, | ||
65 | Prev, | ||
66 | } | ||
67 | |||
61 | impl<'a> SyntaxNodeRef<'a> { | 68 | impl<'a> SyntaxNodeRef<'a> { |
62 | pub fn leaf_text(self) -> Option<&'a SmolStr> { | 69 | pub fn leaf_text(self) -> Option<&'a SmolStr> { |
63 | self.0.leaf_text() | 70 | self.0.leaf_text() |
@@ -71,6 +78,12 @@ impl<'a> SyntaxNodeRef<'a> { | |||
71 | ::algo::walk::WalkEvent::Exit(_) => None, | 78 | ::algo::walk::WalkEvent::Exit(_) => None, |
72 | }) | 79 | }) |
73 | } | 80 | } |
81 | pub fn siblings(self, direction: Direction) -> impl Iterator<Item=SyntaxNodeRef<'a>> { | ||
82 | ::algo::generate(Some(self), move |&node| match direction { | ||
83 | Direction::Next => node.next_sibling(), | ||
84 | Direction::Prev => node.prev_sibling(), | ||
85 | }) | ||
86 | } | ||
74 | } | 87 | } |
75 | 88 | ||
76 | impl<R: TreeRoot<RaTypes>> SyntaxNode<R> { | 89 | impl<R: TreeRoot<RaTypes>> SyntaxNode<R> { |