Expand description
Byte-range text edits.
Edit is the parser’s one edit currency: a byte range in some old text plus
the string that replaces it. Everything here is pure text manipulation with no
parser content; [super::reparse] re-exports it so parser::Edit is the single
path the parser layer uses. Converting LSP didChange content changes into
these lives host-side (crate::lsp in the root crate), which keeps this crate
free of protocol dependencies and wasm-clean.
Edits reaching the reparse are untrusted. A language server can hand over a
chain staged against a buffer that has since moved, and slicing on a stale range
is a panic in an analysis query rather than a wrong answer. So every consumer
validates before it slices: try_apply_edits is the apply-and-verify guard,
and reconstructing the current buffer from an old snapshot plus a chain is what
proves the chain is the exact transform between them.
Structs§
- Edit
- A single contiguous text edit: replace
range(a byte range in the old text) withinsert.
Functions§
- apply_
edits - Apply
editstooldleft-to-right, each expressed against the text its predecessors produced — the shape an LSPdidChangebatch arrives in. - diff_
edit - Recover a single contiguous
Editfrom a pair of whole texts by stripping the common prefix and suffix. - try_
apply_ edits apply_editsfor an edit chain of unproven provenance:Nonewhen any edit does not fit the text its predecessors produced.