aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src/yellow
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libsyntax2/src/yellow')
-rw-r--r--crates/libsyntax2/src/yellow/green.rs17
-rw-r--r--crates/libsyntax2/src/yellow/syntax.rs6
2 files changed, 18 insertions, 5 deletions
diff --git a/crates/libsyntax2/src/yellow/green.rs b/crates/libsyntax2/src/yellow/green.rs
index f505b26d7..700f2704f 100644
--- a/crates/libsyntax2/src/yellow/green.rs
+++ b/crates/libsyntax2/src/yellow/green.rs
@@ -1,8 +1,8 @@
1use std::sync::Arc; 1use std::sync::Arc;
2use { 2
3 SyntaxKind, TextUnit, 3use smol_str::SmolStr;
4 smol_str::SmolStr, 4
5}; 5use {SyntaxKind, TextUnit};
6 6
7#[derive(Clone, Debug)] 7#[derive(Clone, Debug)]
8pub(crate) enum GreenNode { 8pub(crate) enum GreenNode {
@@ -31,7 +31,7 @@ impl GreenNode {
31 31
32 pub fn text_len(&self) -> TextUnit { 32 pub fn text_len(&self) -> TextUnit {
33 match self { 33 match self {
34 GreenNode::Leaf { text, ..} => TextUnit::of_str(text.as_str()), 34 GreenNode::Leaf { text, .. } => TextUnit::of_str(text.as_str()),
35 GreenNode::Branch(b) => b.text_len(), 35 GreenNode::Branch(b) => b.text_len(),
36 } 36 }
37 } 37 }
@@ -54,6 +54,13 @@ impl GreenNode {
54 } 54 }
55 } 55 }
56 } 56 }
57
58 pub fn leaf_text(&self) -> Option<SmolStr> {
59 match self {
60 GreenNode::Leaf { text, .. } => Some(text.clone()),
61 GreenNode::Branch(_) => None,
62 }
63 }
57} 64}
58 65
59#[derive(Clone, Debug)] 66#[derive(Clone, Debug)]
diff --git a/crates/libsyntax2/src/yellow/syntax.rs b/crates/libsyntax2/src/yellow/syntax.rs
index 00f76e51c..b264e008a 100644
--- a/crates/libsyntax2/src/yellow/syntax.rs
+++ b/crates/libsyntax2/src/yellow/syntax.rs
@@ -1,5 +1,7 @@
1use std::{fmt, sync::Arc}; 1use std::{fmt, sync::Arc};
2 2
3use smol_str::SmolStr;
4
3use { 5use {
4 yellow::{RedNode, TreeRoot, SyntaxRoot, RedPtr}, 6 yellow::{RedNode, TreeRoot, SyntaxRoot, RedPtr},
5 SyntaxKind::{self, *}, 7 SyntaxKind::{self, *},
@@ -116,6 +118,10 @@ impl<R: TreeRoot> SyntaxNode<R> {
116 self.first_child().is_none() 118 self.first_child().is_none()
117 } 119 }
118 120
121 pub fn leaf_text(&self) -> Option<SmolStr> {
122 self.red().green().leaf_text()
123 }
124
119 fn red(&self) -> &RedNode { 125 fn red(&self) -> &RedNode {
120 unsafe { self.red.get(&self.root) } 126 unsafe { self.red.get(&self.root) }
121 } 127 }