From 8e42f26965483e96b4bb8113a04075c6a9d68ec6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 31 Dec 2017 20:41:15 +0300 Subject: Debug for Node --- src/tree/mod.rs | 15 +++++++++++++-- 1 file 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> { self.data().kind } + pub fn range(&self) -> TextRange { + self.data().range + } + pub fn text(&self) -> &'f str { - let range = self.data().range; - &self.file.text.as_str()[range] + &self.file.text.as_str()[self.range()] } pub fn parent(&self) -> Option> { @@ -78,6 +81,8 @@ impl<'f> Node<'f> { } } + + pub struct Children<'f> { next: Option>, } @@ -115,4 +120,10 @@ impl ::std::ops::IndexMut for Vec { fn index_mut(&mut self, NodeIdx(idx): NodeIdx) -> &mut NodeData { &mut self[idx as usize] } +} + +impl<'f> fmt::Debug for Node<'f> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + write!(fmt, "{:?}@{:?}", self.kind(), self.range()) + } } \ No newline at end of file -- cgit v1.2.3