sigildocs

(sigil lsp positions)

(sigil lsp positions) - Position and range helpers for LSP.

LSP uses 0-based line and character indices, where character indices are UTF-16 code units. Sigil's reader/formatter uses 1-based line and column (codepoints). This module converts between the two representations.

Exports

positionprocedure

Build an LSP Position alist (0-based line, 0-based character).

rangeprocedure

Build an LSP Range alist from two positions.

Convert 1-based line/column (Sigil reader convention) to an LSP Position. Columns of 0 are clamped to 0; otherwise decremented.

Zero-width range at 1-based line/col, used for point diagnostics.

Whole-line range at 0-based line index, spanning to next line start.

Range covering the entire text, used for full document formatting.

Convert a byte/char offset in TEXT to (values line0 char0).

Inverse of offset->line-col. Returns a 0-based offset or #f if the line/column lies past the end of TEXT.

Return the identifier at 0-based LINE/CHAR in TEXT, or #f if the position does not lie inside one. Returned as a string.