feat(chunk): added hierarchical tree visualization for chunk parent-child relationships

- Enhanced chunk listing output with hierarchical tree visualization showing parent-child relationships and signatures.
- Refactored chunk display logic into recursive emit_children function to support nested tree traversal.
This commit is contained in:
can1357
2026-04-08 13:34:01 +02:00
parent 2bdc80eedc
commit b2bad682d4
+32 -6
View File
@@ -411,13 +411,39 @@ impl ChunkState {
}
if selector.as_deref() == Some("?") {
let mut lines = vec![format!("{} chunks:", params.display_path)];
for chunk in self.inner.chunks().filter(|chunk| !chunk.path.is_empty()) {
lines.push(format!(
" {}#{} L{}-L{}",
chunk.path, chunk.checksum, chunk.start_line, chunk.end_line,
));
let mut lines = vec![format!("{} chunks (dot-joined paths):", params.display_path)];
fn emit_children(
state: &ChunkStateInner,
children: &[String],
prefix: &str,
depth: usize,
lines: &mut Vec<String>,
) {
let count = children.len();
for (index, child_path) in children.iter().enumerate() {
let Some(child) = state.chunk(child_path) else {
continue;
};
let is_last = index + 1 == count;
let connector = if is_last { "└── " } else { "├── " };
let leaf = child.path.rsplit('.').next().unwrap_or(&child.path);
let dot = if depth > 0 { "." } else { "" };
lines.push(format!(
"{prefix}{connector}{dot}{leaf}#{} L{}-L{}",
child.checksum, child.start_line, child.end_line,
));
let continuation = if is_last { " " } else { "│ " };
if let Some(sig) = child.signature.as_deref() {
lines.push(format!("{prefix}{continuation} {sig}"));
}
if !child.children.is_empty() {
let next_prefix = format!("{prefix}{continuation}");
emit_children(state, &child.children, &next_prefix, depth + 1, lines);
}
}
}
let root_children = &self.inner.tree().root_children;
emit_children(&self.inner, root_children, "", 0, &mut lines);
return Ok(ReadResult { text: lines.join("\n"), chunk: None });
}