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§

diagnose
Parse text as SQL and return diagnostics for any parse errors and variable issues.