aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/yellow
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-10-02 16:14:33 +0100
committerAleksey Kladov <[email protected]>2018-10-02 16:14:33 +0100
commit1a2a8dec14ec04ea8eeccae99fd885e7a280e45b (patch)
treef94bb3a8bd47e3612ef29e815532c07d7871fa0f /crates/ra_syntax/src/yellow
parentd323c81d5cc6a198239285abcede2166181d8f39 (diff)
Make siblings an inherent method
Diffstat (limited to 'crates/ra_syntax/src/yellow')
-rw-r--r--crates/ra_syntax/src/yellow/mod.rs13
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)]
63pub enum Direction {
64 Next,
65 Prev,
66}
67
61impl<'a> SyntaxNodeRef<'a> { 68impl<'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
76impl<R: TreeRoot<RaTypes>> SyntaxNode<R> { 89impl<R: TreeRoot<RaTypes>> SyntaxNode<R> {