diff options
author | Aleksey Kladov <[email protected]> | 2017-12-31 17:41:15 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2017-12-31 17:41:15 +0000 |
commit | 8e42f26965483e96b4bb8113a04075c6a9d68ec6 (patch) | |
tree | 8ebb08319d70722095874d48b95b5312e3a1475b /src | |
parent | f16fed18b3587637f4e50ac03aecdbc6f0e8d1fa (diff) |
Debug for Node
Diffstat (limited to 'src')
-rw-r--r-- | src/tree/mod.rs | 15 |
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 | |||
81 | pub struct Children<'f> { | 86 | pub 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 | |||
125 | impl<'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 |