Composer.LSP.Position (composer v0.2.0)

Copy Markdown View Source

Converts columns between Composer and the Language Server Protocol.

Composer's columns (Composer.Lint.Diagnostic, Composer.Recipe.Locator) are 1-based and count grapheme clusters, as Elixir's tokenizer does. An LSP character is 0-based and counts code units of the negotiated position encoding: UTF-16 (the protocol's default), UTF-8 bytes or UTF-32 codepoints. Lines differ only by one (1-based against 0-based).

Conversion needs the line's text. With no text (a line past the end of the file), a column passes through, shifted by one.

Summary

Functions

The Composer column (1-based, in graphemes) of LSP character on a line of text line_text. A position inside a grapheme snaps to its start.

Picks the position encoding from the client's positionEncodings (nil when it sent none), as {encoding, wire_name}.

The LSP character of Composer column (1-based, in graphemes) on a line of text line_text.

The length of string in code units of encoding.

Types

encoding()

@type encoding() :: :utf8 | :utf16 | :utf32

Functions

from_lsp(line_text, character, encoding)

@spec from_lsp(String.t() | nil, non_neg_integer(), encoding()) :: pos_integer()

The Composer column (1-based, in graphemes) of LSP character on a line of text line_text. A position inside a grapheme snaps to its start.

negotiate(offered)

@spec negotiate([String.t()] | nil) :: {encoding(), String.t()}

Picks the position encoding from the client's positionEncodings (nil when it sent none), as {encoding, wire_name}.

to_lsp(line_text, column, encoding)

@spec to_lsp(String.t() | nil, pos_integer(), encoding()) :: non_neg_integer()

The LSP character of Composer column (1-based, in graphemes) on a line of text line_text.

units(string, atom)

@spec units(String.t(), encoding()) :: non_neg_integer()

The length of string in code units of encoding.