pub fn incremental_reparse(old_tree: &SyntaxNode, edit: &TextEdit) -> ParseExpand description
Reparse after applying edit to old_tree’s source.
§Implementation — smart sub-tree splice with whole-file fallback
When the incremental feature is enabled (default-on, cy-li5):
- Locate the smallest
STATEMENTnode inold_treethat fully containsedit.rangeviarowan::SyntaxNode::covering_elementand an upward walk to the nearestSTATEMENTancestor. - Reconstruct the new text for that statement’s span by stitching
old_text[stmt.start..edit.start] + edit.replacement + old_text[edit.end..stmt.end]. - Lex the candidate statement text in isolation. If a top-level
;orUNIONappears inside the new text, the edit changed the statement count — bail to whole-file. - Parse the candidate text as a wrapped source-file, extract the
STATEMENTgreen sub-tree, and splice it in viarowan::SyntaxNode::replace_with. - Re-derive errors by full re-parse of the new source. This step
keeps the public-API invariant (errors match what
parse(new_src)would produce) honest. A future tranche may incrementally reconcile errors, but that is not a cy-li5 deliverable — correctness gates the optimization.
If any of the bail conditions trip (no enclosing STATEMENT, edit
straddles a ;, top-level separator introduced/removed, candidate
text fails to parse to a single STATEMENT), the implementation falls
back to a whole-file parse. The whole-file path is also taken
unconditionally when the incremental feature is disabled — that
behaviour is preserved as the slow-but-always-correct A/B baseline
(cy-zv0).
§Caveat — bench observability
The bench_incremental_edit 2k/1k ratio gate is driven by
Database::edit_file, which today reduces this function’s return
value to its syntax().to_string() and feeds the string back into
Salsa. As a result, the green-tree splice savings inside this
function are not yet observable end-to-end at the bench. Threading
the precomputed Parse into Salsa as a memo is a separate
follow-up tranche; the cy-li5 acceptance criterion that the bench
ratio drops below 1.5× depends on that wiring landing.