Skip to main content

Module diagnostics

Module diagnostics 

Source
Expand description

Source-positioned diagnostics decoupled from any output format.

PositionalDiagnostic is the neutral intermediate representation: a severity, a file path, a source string, and a byte range within that source. The LSP server wraps it into tower_lsp::lsp_types::Diagnostic by converting the byte range to line/column via a ropey::Rope; the CLI wraps it into an annotate_snippets snippet for terminal output.

Both consumers share the locator helpers in this module (find_identifier, find_identifier_after, locate_plan, locate_catalog, locate_typecheck, locate_validation) which derive byte ranges from mz_sql and validation errors that carry only an identifier name (no offset). The module also exposes format_typecheck_kind and format_validation_kind, the shared formatters that turn an error kind into a (message, footers, suggestions) triple β€” footers carry class-level advice, suggestions carry mechanical edits encoded as byte-range replacements.

StructsΒ§

PositionalDiagnostic πŸ”’
A diagnostic anchored to a byte range within a single source file.
Replacement πŸ”’
A single replacement: substitute byte_range of the source with replacement.
Suggestion πŸ”’
One or more interchangeable replacements offered under a single help title. Renders as a rustc-style multi-suggestion block:

EnumsΒ§

Severity πŸ”’

FunctionsΒ§

column_display πŸ”’
Format table.column as a dotted PostgreSQL reference (relation + column). Each component is rendered as its raw identifier β€” no outer quotes β€” so a reader interprets the dot as a separator rather than as part of a single quoted identifier.
fallback_catalog πŸ”’
fallback_plan πŸ”’
find_identifier πŸ”’
Find the first whole-word occurrence of name in source.
find_identifier_after πŸ”’
Same as find_identifier but starts the search at start_byte. Returns absolute byte ranges into source.
format_catalog πŸ”’
format_plan πŸ”’
format_typecheck_kind πŸ”’
Build the (message, footers, suggestions) triple for one typecheck kind.
format_validation_kind πŸ”’
Build the (message, footers, suggestions) triple for a validation kind.
is_ident_byte πŸ”’
last_component πŸ”’
Strip qualifying prefixes from a dotted identifier, returning the final component. schema.table β†’ table; t β†’ t.
locate_catalog πŸ”’
Locate the byte range a CatalogError points at within source.
locate_plan πŸ”’
Locate the byte range a PlanError points at within source.
locate_replacement πŸ”’
Find the byte range of needle to replace.
locate_typecheck πŸ”’
Locate the byte range a typecheck error points at within source.
locate_validation πŸ”’
Locate the byte range of the declared identifier in a *Mismatch validation error. Returns None for variants that don’t carry a declared name we can rewrite.
mismatch_pair πŸ”’
Some((declared, expected)) if kind is a rewritable *Mismatch variant β€” the trailing identifier the user wrote, plus the one their file path requires.
mismatch_suggestion πŸ”’