LavaUI docs

struct Cache

Swift

struct Cache

Per-line spans plus the state each line started in, updated incrementally as the buffer edits rather than re-lexed whole on every keystroke — the property a stateful lexer needs and a rule list already got for free from being stateless.

Rebuilding is a two-part diff against what is cached:

  • a common prefix of unchanged lines needs no work, and fixes the state the first changed line starts from (it is whatever was already cached there — nothing above it could have changed);
  • re-lexing then stops the moment a line's recomputed start state and text both match what was cached there before, because from that point on every line downstream would recompute to exactly what it already has. The second check only fires when the line count hasn't changed — an inserted or deleted line shifts every index below it, so comparing old and new content at the same index would compare the wrong lines. Missing that convergence in the insert/delete case just means re-lexing to the end of the file instead of stopping early: slower, never wrong.

Sources/LavaText/Highlighting.swift:262

Constructors

init()

Not documented.

Sources/LavaText/Highlighting.swift:267

Methods

func spans(atRow row: Int) -> [HighlightSpan]

Spans for row, valid only immediately after update(lines:with:) with the same row in range.

Sources/LavaText/Highlighting.swift:271

mutating func update(lines newLines: [Substring], with highlighter: SyntaxHighlighter)

Not documented.

Sources/LavaText/Highlighting.swift:275