resolve: build the resolved document field by field instead of cloning the input tree to discard it

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-28 00:58:55 +01:00
commit 2fcd522516

View file

@ -92,7 +92,17 @@ pub fn resolve(document: &SurfaceDocument, port: &dyn StatePort, limits: &Limits
let tree = root.and_then(|root| {
diagnostics.extend(validate::check(&root, limits, &document.record_key()));
let refused = diagnostics.iter().any(|diagnostic| diagnostic.code.refuses_document());
(!refused).then(|| ResolvedTree { document: SurfaceDocument { root, ..document.clone() } })
// Field by field: `..document.clone()` would clone the whole input tree to discard it.
(!refused).then(|| ResolvedTree {
document: SurfaceDocument {
provider_id: document.provider_id.clone(),
label: document.label.clone(),
version: document.version,
title: document.title.clone(),
root,
commands: document.commands.clone(),
},
})
});
Resolution { tree, diagnostics, reads }
}