mirror of
https://github.com/RGBCube/cstree
synced 2025-07-28 01:27:44 +00:00
add debug implementations for nodes/tokens with resolver
This commit is contained in:
parent
424a86d8cc
commit
911775b731
2 changed files with 49 additions and 1 deletions
|
@ -1,6 +1,6 @@
|
|||
use std::{
|
||||
cell::UnsafeCell,
|
||||
fmt::Write,
|
||||
fmt::{self, Write},
|
||||
hash::{Hash, Hasher},
|
||||
iter, ptr,
|
||||
sync::atomic::{AtomicU32, Ordering},
|
||||
|
@ -872,6 +872,24 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<L: Language, D, R> fmt::Debug for SyntaxNode<L, D, R>
|
||||
where
|
||||
R: Resolver,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", Self::debug(self, self.resolver().as_ref(), f.alternate()))
|
||||
}
|
||||
}
|
||||
|
||||
impl<L: Language, D, R> fmt::Display for SyntaxNode<L, D, R>
|
||||
where
|
||||
R: Resolver,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", Self::display(self, self.resolver().as_ref()))
|
||||
}
|
||||
}
|
||||
|
||||
impl<L: Language, D, R> SyntaxToken<L, D, R> {
|
||||
fn new(parent: &SyntaxNode<L, D, R>, index: u32, offset: TextSize) -> SyntaxToken<L, D, R> {
|
||||
Self {
|
||||
|
@ -1000,6 +1018,24 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<L: Language, D, R> fmt::Debug for SyntaxToken<L, D, R>
|
||||
where
|
||||
R: Resolver,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", Self::debug(self, self.parent().resolver().as_ref()))
|
||||
}
|
||||
}
|
||||
|
||||
impl<L: Language, D, R> fmt::Display for SyntaxToken<L, D, R>
|
||||
where
|
||||
R: Resolver,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", Self::display(self, self.parent().resolver().as_ref()))
|
||||
}
|
||||
}
|
||||
|
||||
impl<L: Language, D, R> SyntaxElement<L, D, R> {
|
||||
fn new(
|
||||
element: GreenElementRef<'_>,
|
||||
|
|
|
@ -147,11 +147,23 @@ fn inline_resolver() {
|
|||
let leaf1_0 = leaf1_0.into_token().unwrap();
|
||||
assert_eq!(leaf1_0.text(), "1.0");
|
||||
assert_eq!(leaf1_0.text_range(), TextRange::at(6.into(), 3.into()));
|
||||
assert_eq!(format!("{}", leaf1_0), leaf1_0.text());
|
||||
assert_eq!(format!("{:?}", leaf1_0), "SyntaxKind(5)@6..9 \"1.0\"");
|
||||
}
|
||||
{
|
||||
let node2 = tree.children().nth(2).unwrap();
|
||||
assert_eq!(node2.text(), "2.02.12.2");
|
||||
let resolver = node2.resolver();
|
||||
assert_eq!(node2.resolve_text(resolver.as_ref()), node2.text());
|
||||
assert_eq!(format!("{}", node2).as_str(), node2.text());
|
||||
assert_eq!(format!("{:?}", node2), "SyntaxKind(6)@9..18");
|
||||
assert_eq!(
|
||||
format!("{:#?}", node2),
|
||||
r#"SyntaxKind(6)@9..18
|
||||
SyntaxKind(7)@9..12 "2.0"
|
||||
SyntaxKind(8)@12..15 "2.1"
|
||||
SyntaxKind(9)@15..18 "2.2"
|
||||
"#
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue