aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/tree/mod.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/tree/mod.rs b/src/tree/mod.rs
index 7c4162a68..6bacb46ef 100644
--- a/src/tree/mod.rs
+++ b/src/tree/mod.rs
@@ -56,9 +56,12 @@ impl<'f> Node<'f> {
56 self.data().kind 56 self.data().kind
57 } 57 }
58 58
59 pub fn range(&self) -> TextRange {
60 self.data().range
61 }
62
59 pub fn text(&self) -> &'f str { 63 pub fn text(&self) -> &'f str {
60 let range = self.data().range; 64 &self.file.text.as_str()[self.range()]
61 &self.file.text.as_str()[range]
62 } 65 }
63 66
64 pub fn parent(&self) -> Option<Node<'f>> { 67 pub fn parent(&self) -> Option<Node<'f>> {
@@ -78,6 +81,8 @@ impl<'f> Node<'f> {
78 } 81 }
79} 82}
80 83
84
85
81pub struct Children<'f> { 86pub struct Children<'f> {
82 next: Option<Node<'f>>, 87 next: Option<Node<'f>>,
83} 88}
@@ -115,4 +120,10 @@ impl ::std::ops::IndexMut<NodeIdx> for Vec<NodeData> {
115 fn index_mut(&mut self, NodeIdx(idx): NodeIdx) -> &mut NodeData { 120 fn index_mut(&mut self, NodeIdx(idx): NodeIdx) -> &mut NodeData {
116 &mut self[idx as usize] 121 &mut self[idx as usize]
117 } 122 }
123}
124
125impl<'f> fmt::Debug for Node<'f> {
126 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
127 write!(fmt, "{:?}@{:?}", self.kind(), self.range())
128 }
118} \ No newline at end of file 129} \ No newline at end of file