Skip to main content

Crate sql_dialect_fmt_lsp

Crate sql_dialect_fmt_lsp 

Source
Expand description

LSP feature logic for Snowflake SQL: formatting edits, parse diagnostics, and semantic tokens.

This module is deliberately transport-free (it never touches stdio or an lsp-server connection), so every feature is a pure &str -> data function that is unit-testable. The binary ([crate::main]) is the thin adapter that wires these into a language server.

Positions follow the LSP convention: zero-based lines and UTF-16 column offsets.

Structs§

LineIndex
Maps byte offsets into a document to LSP Positions (UTF-16 columns).

Functions§

apply_change
Apply one textDocument/didChange content change to text, returning the new document.
diagnostics
Diagnostics for textDocument/publishDiagnostics: both lexer and parser errors. Neither stage ever fails, so this is the set of recovered errors (empty for clean input).
folding_ranges
Folding ranges for textDocument/foldingRange: one region per multi-line top-level statement, so an editor can collapse each statement in a script. The CST’s root children are the statements.
format_edits
The edits to apply for textDocument/formatting: a single whole-document replacement, or an empty list when the input is already formatted (so the editor records no change).
hover
Hover information for textDocument/hover: the keyword/type/symbol description at position, rendered as Markdown with an optional docs link, scoped to the hovered token’s range.
semantic_tokens
The delta-encoded semantic tokens for textDocument/semanticTokens/full.
token_modifiers
The semantic-token modifier legend, mirrored from semantic::SemanticTokenModifiers::LEGEND. A token’s token_modifiers_bitset is decoded bit-by-bit against this slice, so it too must match the highlighter.
token_types
The semantic-token type legend, mirrored from the single source of truth in sql-dialect-fmt-highlight (semantic::SemanticTokenType::LEGEND). A token’s token_type field is an index into this slice, so the order here is the contract with the editor (declared in the server’s capabilities) and must equal the highlighter’s legend — otherwise an editor would decode our token types against the wrong names.