diff options
Diffstat (limited to 'crates/libsyntax2/src/yellow')
-rw-r--r-- | crates/libsyntax2/src/yellow/syntax.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/crates/libsyntax2/src/yellow/syntax.rs b/crates/libsyntax2/src/yellow/syntax.rs index b264e008a..bb390751a 100644 --- a/crates/libsyntax2/src/yellow/syntax.rs +++ b/crates/libsyntax2/src/yellow/syntax.rs | |||
@@ -89,7 +89,15 @@ impl<R: TreeRoot> SyntaxNode<R> { | |||
89 | } | 89 | } |
90 | 90 | ||
91 | pub fn first_child(&self) -> Option<SyntaxNode<R>> { | 91 | pub fn first_child(&self) -> Option<SyntaxNode<R>> { |
92 | self.children().next() | 92 | let red = self.red().get_child(0)?; |
93 | Some(SyntaxNode { root: self.root.clone(), red }) | ||
94 | } | ||
95 | |||
96 | pub fn last_child(&self) -> Option<SyntaxNode<R>> { | ||
97 | let n = self.red().n_children(); | ||
98 | let n = n.checked_sub(1)?; | ||
99 | let red = self.red().get_child(n)?; | ||
100 | Some(SyntaxNode { root: self.root.clone(), red }) | ||
93 | } | 101 | } |
94 | 102 | ||
95 | pub fn next_sibling(&self) -> Option<SyntaxNode<R>> { | 103 | pub fn next_sibling(&self) -> Option<SyntaxNode<R>> { |