Keep context implementations with their document models

This commit is contained in:
2026-11-30 18:56:28 +08:00
parent 455a3580d6
commit 66b6910eb1
9 changed files with 110 additions and 106 deletions
+23
View File
@@ -1,5 +1,7 @@
use std::collections::{HashMap, HashSet};
use super::contextualize::Contextualize;
use thiserror::Error;
use crate::{Document, DocumentId};
@@ -79,3 +81,24 @@ impl DocumentTree {
.chain(self.descendants.iter().map(|(depth, node)| (*depth, node)))
}
}
impl Contextualize for DocumentTree {
fn render_context(&self) -> String {
let mut text = String::new();
let mut first_line = true;
for (depth, node) in self.nodes() {
let rendered = node.render_context();
for line in rendered.split('\n') {
if !first_line {
text.push('\n');
}
first_line = false;
for _ in 1..depth {
text.push_str(" ");
}
text.push_str(line);
}
}
text
}
}