Skip to main content

map_range_through_edit

Function map_range_through_edit 

Source
pub fn map_range_through_edit(
    range: TextRange,
    edit: &Edit,
) -> Option<TextRange>
Expand description

Map a TextRange taken against the text before edit to its position in the text after edit.

Returns None when the edit’s replaced range overlaps the node’s interior: a (kind, range) handle cannot promise the node survived an edit inside it (its text, and possibly its kind, may have changed). Comparisons are half-open, so the boundary cases are deterministic: an edit ending exactly at the node’s start shifts the node (it survives), an edit starting exactly at the node’s end leaves it unchanged (it survives), and an insertion strictly inside the node returns None. A zero-length node sitting at an insertion point is treated as preceding the insertion (unchanged).

Note: the arity crate’s incremental::parsed_document recovers a single spanning diff_edit, so several disjoint keystrokes coalesce into one wide edit. That only widens the overlap and yields None more often (more position-based re-resolution by the caller) — it never produces a wrong mapping. Feeding precise per-change LSP edits would shrink the edit and reduce those fallbacks.