Skip to main content

Module diagnostics

Module diagnostics 

Source
Expand description

LSP-specific diagnostic emission.

Each producer in this module first builds a PositionalDiagnostic using the shared locator helpers, then converts it to a tower_lsp::lsp_types::Diagnostic via to_lsp using a Rope for byte-offset → line/column conversion.

Three tiers of diagnostics:

  • Per-keystroke diagnostics (diagnose()) — Resolves psql-style variables before parsing. Unresolved variables produce positioned diagnostics (ERROR or WARNING depending on the warn pragma). The resolved SQL is then parsed with mz_sql_parser::parser::parse_statements() and any parse error positions are mapped back to original-text offsets via resolved_to_original.

  • On-save validation errors (validation_diagnostics()) — Converts project-level ValidationErrors into LSP diagnostics grouped by file. When an error carries a byte offset (most statement-level errors), the diagnostic is positioned at the correct line/column. File-level errors (e.g., missing CREATE statement) fall back to (0, 0).

  • On-save typecheck errors (typecheck_diagnostics()) — Inspects the structured upstream error to position the diagnostic. See locate_typecheck for the dispatch.

Functions§

append_detail_and_hints 🔒
Append \ndetail: <detail> (when present) and one \nhint: <footer> line per footer to message. Preserves the human-readable advice for editors that don’t render code actions.
attach_quickfix_data 🔒
Encode suggestions as the QuickFixData JSON payload on diag.data for the LSP code-action handler. No-op when suggestions is empty.
build_error_diagnostic 🔒
Build an error-severity LSP Diagnostic for byte_range in rope.
diagnose
Parse text as SQL and return diagnostics for any parse errors and variable issues.
offset_to_position 🔒
Convert a byte offset to an LSP Position (line, column) using a Rope.
parse_positional 🔒
Build PositionalDiagnostics for parse errors and unresolved variables in text. All positions are in original-text byte space (post-substitution parser offsets are mapped back via resolved_to_original).
position_to_offset 🔒
Convert an LSP Position into a byte offset using a Rope.
read_source 🔒
to_lsp 🔒
Convert a PositionalDiagnostic to an LSP Diagnostic.
typecheck_diagnostics 🔒
Convert a TypeCheckError into LSP diagnostics grouped by file path.
utf16_len 🔒
validation_diagnostics 🔒
Convert ValidationErrors into LSP diagnostics grouped by file path.