Skip to main content

map_live_offset_to_compiled

Function map_live_offset_to_compiled 

Source
pub fn map_live_offset_to_compiled(
    live: &str,
    compiled: &str,
    pos: usize,
) -> usize
Expand description

Map a byte offset in the live buffer to the same place in compiled, the text the AST (and so scope_ranges) was built from.

Incomplete code like obj. rarely compiles, so the cache usually lags the buffer. Without this, every byte typed above the cursor since the last good build shifts the scope lookup, and enough of them land it in a sibling function. The two texts are compared by common prefix and suffix: offsets before the edited region are unchanged, offsets after it shift by the length difference. Offsets inside it are mapped from the suffix end, since the cursor is normally where the most recent typing is.