Debug for Node

This commit is contained in:
Aleksey Kladov 2017-12-31 20:41:15 +03:00
parent f16fed18b3
commit 8e42f26965

View file

@ -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<Node<'f>> {
@ -78,6 +81,8 @@ impl<'f> Node<'f> {
}
}
pub struct Children<'f> {
next: Option<Node<'f>>,
}
@ -116,3 +121,9 @@ impl ::std::ops::IndexMut<NodeIdx> for Vec<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())
}
}