Expand description
LSP code-action support.
Owns four concerns that all serve the textDocument/codeAction flow:
QuickFixDatapayload (SuggestionData,ReplacementData,suggestions_to_data) — JSON sidecar attached toDiagnostic.dataso the same suggestion data round-trips from a diagnostic to a follow-upcodeActionrequest.- Builder (
build_code_actions) — turns aCodeActionParamsrequest back into oneCodeActionper alternative. Pure; no I/O. - Fuzzy enrichment (
Candidates,harvest_candidates,fuzzy_suggestions,did_you_mean) — for catalog errors the typechecker doesn’t suggest replacements for (UnknownItem,UnknownSchema,UnknownDatabase,UnknownCluster), generate suggestions LSP-side by Damerau-Levenshtein-matching against names harvested from the project cache.
Structs§
- Candidates 🔒
- Per-kind candidate name pools harvested from the project cache. Empty vectors are valid — they just mean no fuzzy suggestions for that kind.
- Quick
FixData 🔒 - JSON payload riding on
Diagnostic.dataso thecode_actionhandler can rebuild aWorkspaceEditwithout re-running the typecheck. - Replacement
Data 🔒 - Suggestion
Data 🔒
Constants§
- MAX_
DID_ 🔒YOU_ MEAN - Maximum number of suggestions returned by
did_you_mean.
Functions§
- action_
for_ 🔒alt - build_
code_ 🔒actions - Build the list of quick-fix code actions for a
textDocument/codeActionrequest. Inspects each diagnostic’sdatafield forQuickFixDataand emits oneCodeActionper alternative. - byte_
range_ 🔒to_ lsp - did_
you_ 🔒mean - Return up to
MAX_DID_YOU_MEANclosest names fromcandidatestoneedle, sorted by Damerau-Levenshtein distance ascending. Names whose distance exceedsmax(2, needle.len() / 3)are filtered out so unrelated matches don’t surface as quick fixes. - fuzzy_
suggestions 🔒 - LSP-side enrichment: for
Catalog::Unknown{Item,Schema,Database,Cluster}, fuzzy-match the offending name against the corresponding pool and return oneSuggestioncontaining the closest alternatives. Returns an empty vec for variants we don’t enrich (everything else, includingUnknownColumn/UnknownFunctionwhose suggestions come from upstream). - harvest_
candidates 🔒 - Build a
Candidatesset from the project cache: every project item name intoitems, every schema intoschemas, every database intodatabases, and the unique non-empty cluster names referenced by project objects intoclusters. Returns an emptyCandidateswhencacheisNone. - suggestions_
to_ 🔒data - Convert the byte-range-flavored
Suggestions produced by the diagnostics formatter into LSP-shapedSuggestionDatausingropeto map byte offsets to line/column. ReturnsNonewhensuggestionsis empty so the caller can leaveDiagnostic.dataunset.