(
node: &SyntaxNode,
depth: usize,
index: &CompressedIndex,
result: &mut Vec<String>,
)
| 1374 | } |
| 1375 | |
| 1376 | fn tree_to_string_impl( |
| 1377 | node: &SyntaxNode, |
| 1378 | depth: usize, |
| 1379 | index: &CompressedIndex, |
| 1380 | result: &mut Vec<String>, |
| 1381 | ) { |
| 1382 | let indent = " ".repeat(depth); |
| 1383 | if let Some((s, e)) = index.node_range(node) { |
| 1384 | result.push(format!("{}{:?}@{}..{}", indent, node.kind(), s, e)); |
| 1385 | } else { |
| 1386 | // empty node |
| 1387 | result.push(format!("{}{:?}@0..0", indent, node.kind())); |
| 1388 | } |
| 1389 | |
| 1390 | for child in node.children_with_tokens() { |
| 1391 | match child { |
| 1392 | rowan::NodeOrToken::Node(child_node) => { |
| 1393 | tree_to_string_impl(&child_node, depth + 1, index, result); |
| 1394 | } |
| 1395 | rowan::NodeOrToken::Token(token) => { |
| 1396 | use crate::lexer::SyntaxKind as K; |
| 1397 | if matches!(token.kind(), K::Whitespace | K::LineComment) { |
| 1398 | continue; |
| 1399 | } |
| 1400 | let token_indent = " ".repeat(depth + 1); |
| 1401 | if let Some((s, e)) = index.token_range(&token) { |
| 1402 | result.push(format!( |
| 1403 | "{}{:?}@{}..{} {:?}", |
| 1404 | token_indent, |
| 1405 | token.kind(), |
| 1406 | s, |
| 1407 | e, |
| 1408 | token.text() |
| 1409 | )); |
| 1410 | } |
| 1411 | } |
| 1412 | } |
| 1413 | } |
| 1414 | } |
| 1415 | |
| 1416 | fn expect_tree(input: &str, lines: &[&str]) { |
| 1417 | let node = parse(input).syntax(); |
no test coverage detected
searching dependent graphs…