diff options
Diffstat (limited to 'crates/libsyntax2/src/yellow/syntax.rs')
-rw-r--r-- | crates/libsyntax2/src/yellow/syntax.rs | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/crates/libsyntax2/src/yellow/syntax.rs b/crates/libsyntax2/src/yellow/syntax.rs index 75b6cb7dc..ede9ad3c8 100644 --- a/crates/libsyntax2/src/yellow/syntax.rs +++ b/crates/libsyntax2/src/yellow/syntax.rs | |||
@@ -6,7 +6,7 @@ use std::{ | |||
6 | use smol_str::SmolStr; | 6 | use smol_str::SmolStr; |
7 | 7 | ||
8 | use { | 8 | use { |
9 | yellow::{GreenNode, RedNode, TreeRoot, SyntaxRoot, RedPtr, RefRoot, OwnedRoot}, | 9 | yellow::{GreenNode, RedNode, TreeRoot, SyntaxRoot, RedPtr, RefRoot, OwnedRoot, SyntaxText}, |
10 | SyntaxKind::{self, *}, | 10 | SyntaxKind::{self, *}, |
11 | TextRange, TextUnit, | 11 | TextRange, TextUnit, |
12 | }; | 12 | }; |
@@ -58,6 +58,13 @@ impl SyntaxNode<OwnedRoot> { | |||
58 | } | 58 | } |
59 | } | 59 | } |
60 | 60 | ||
61 | impl<'a> SyntaxNode<RefRoot<'a>> { | ||
62 | pub(crate) fn leaf_text_ref(self) -> Option<&'a SmolStr> { | ||
63 | let red = unsafe { self.red.get(self.root.syntax_root()) }; | ||
64 | red.green().leaf_text_ref() | ||
65 | } | ||
66 | } | ||
67 | |||
61 | impl<R: TreeRoot> SyntaxNode<R> { | 68 | impl<R: TreeRoot> SyntaxNode<R> { |
62 | pub fn borrowed<'a>(&'a self) -> SyntaxNodeRef<'a> { | 69 | pub fn borrowed<'a>(&'a self) -> SyntaxNodeRef<'a> { |
63 | SyntaxNode { | 70 | SyntaxNode { |
@@ -66,7 +73,7 @@ impl<R: TreeRoot> SyntaxNode<R> { | |||
66 | } | 73 | } |
67 | } | 74 | } |
68 | 75 | ||
69 | pub fn owned<'a>(&'a self) -> SyntaxNode { | 76 | pub fn owned(&self) -> SyntaxNode { |
70 | SyntaxNode { | 77 | SyntaxNode { |
71 | root: self.root.owned(), | 78 | root: self.root.owned(), |
72 | red: self.red, | 79 | red: self.red, |
@@ -82,8 +89,8 @@ impl<R: TreeRoot> SyntaxNode<R> { | |||
82 | TextRange::offset_len(red.start_offset(), red.green().text_len()) | 89 | TextRange::offset_len(red.start_offset(), red.green().text_len()) |
83 | } | 90 | } |
84 | 91 | ||
85 | pub fn text(&self) -> String { | 92 | pub fn text(&self) -> SyntaxText { |
86 | self.red().green().text() | 93 | SyntaxText::new(self.borrowed()) |
87 | } | 94 | } |
88 | 95 | ||
89 | pub fn children(&self) -> impl Iterator<Item = SyntaxNode<R>> { | 96 | pub fn children(&self) -> impl Iterator<Item = SyntaxNode<R>> { |
@@ -91,7 +98,7 @@ impl<R: TreeRoot> SyntaxNode<R> { | |||
91 | let n_children = self.red().n_children(); | 98 | let n_children = self.red().n_children(); |
92 | let root = self.root.clone(); | 99 | let root = self.root.clone(); |
93 | (0..n_children).map(move |i| { | 100 | (0..n_children).map(move |i| { |
94 | let red = unsafe { red.get(&root) }; | 101 | let red = unsafe { red.get(root.syntax_root()) }; |
95 | SyntaxNode { | 102 | SyntaxNode { |
96 | root: root.clone(), | 103 | root: root.clone(), |
97 | red: red.get_child(i).unwrap(), | 104 | red: red.get_child(i).unwrap(), |
@@ -171,7 +178,7 @@ impl<R: TreeRoot> SyntaxNode<R> { | |||
171 | } | 178 | } |
172 | 179 | ||
173 | fn red(&self) -> &RedNode { | 180 | fn red(&self) -> &RedNode { |
174 | unsafe { self.red.get(&self.root) } | 181 | unsafe { self.red.get(self.root.syntax_root()) } |
175 | } | 182 | } |
176 | } | 183 | } |
177 | 184 | ||