Converts between byte-indexed positions and external text position encodings.
Minga stores positions as {line, byte_col} where byte_col is a byte offset within the line. Some external protocols, including LSP, use UTF-16 or UTF-32 character offsets instead. This module keeps that conversion pure so Layer 0 data structures can translate ranges without depending on stateful LSP services.
Summary
Types
An external offset encoding for character positions.
A zero-indexed line and byte-column position.
Functions
Returns the supported encoding strings in client preference order.
Converts an exact external column to a byte column without clamping invalid positions.
Converts an external position map back to a byte-column position.
Negotiates the best offset encoding from a supported list.
Converts a byte-column position to an external position map.
Types
@type encoding() :: :utf8 | :utf16 | :utf32
An external offset encoding for character positions.
@type position() :: {line :: non_neg_integer(), col :: non_neg_integer()}
A zero-indexed line and byte-column position.
Functions
@spec client_supported_encodings() :: [String.t()]
Returns the supported encoding strings in client preference order.
@spec exact_byte_column(String.t(), non_neg_integer(), encoding()) :: {:ok, non_neg_integer()} | {:error, :column_out_of_range | :column_not_boundary}
Converts an exact external column to a byte column without clamping invalid positions.
Converts an external position map back to a byte-column position.
Negotiates the best offset encoding from a supported list.
Prefers UTF-8, then UTF-16, then UTF-32. Falls back to UTF-16 when the server or external source does not advertise support.
Converts a byte-column position to an external position map.