defmodule Localize.Mf2.TreeSitter.Edit do @moduledoc """ Description of a single text change, for incremental reparsing. An edit names the byte range in the *old* source that was replaced and the byte range in the *new* source that took its place, plus the equivalent `{row, column}` points. Tree-sitter uses this to adjust the old parse tree so that unchanged subtrees can be reused when parsing the new source. ### Fields * `start_byte` — byte offset (in both old and new source) at which the change begins. * `old_end_byte` — end of the replaced range in the *old* source. * `new_end_byte` — end of the inserted range in the *new* source. * `start_point`, `old_end_point`, `new_end_point` — `{row, column}` counterparts of the three byte offsets. For a pure insertion `old_end_byte == start_byte`. For a pure deletion `new_end_byte == start_byte`. Both rows and byte offsets must be consistent — if you change rows, update points; if you only change one line, rows are equal. See [`TSInputEdit` in the tree-sitter docs](https://tree-sitter.github.io/tree-sitter/using-parsers#editing) for the full semantics. """ @enforce_keys [ :start_byte, :old_end_byte, :new_end_byte, :start_point, :old_end_point, :new_end_point ] defstruct [ :start_byte, :old_end_byte, :new_end_byte, :start_point, :old_end_point, :new_end_point ] @type point :: {non_neg_integer(), non_neg_integer()} @type t :: %__MODULE__{ start_byte: non_neg_integer(), old_end_byte: non_neg_integer(), new_end_byte: non_neg_integer(), start_point: point(), old_end_point: point(), new_end_point: point() } @doc false @spec to_tuple(t()) :: {non_neg_integer(), non_neg_integer(), non_neg_integer(), point(), point(), point()} def to_tuple(%__MODULE__{} = e) do {e.start_byte, e.old_end_byte, e.new_end_byte, e.start_point, e.old_end_point, e.new_end_point} end end