Skip to main content

Module code_action

Module code_action 

Source
Expand description

LSP code-action support.

Owns four concerns that all serve the textDocument/codeAction flow:

  • QuickFixData payload (SuggestionData, ReplacementData, suggestions_to_data) — JSON sidecar attached to Diagnostic.data so the same suggestion data round-trips from a diagnostic to a follow-up codeAction request.
  • Builder (build_code_actions) — turns a CodeActionParams request back into one CodeAction per 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.
QuickFixData 🔒
JSON payload riding on Diagnostic.data so the code_action handler can rebuild a WorkspaceEdit without re-running the typecheck.
ReplacementData 🔒
SuggestionData 🔒

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/codeAction request. Inspects each diagnostic’s data field for QuickFixData and emits one CodeAction per alternative.
byte_range_to_lsp 🔒
did_you_mean 🔒
Return up to MAX_DID_YOU_MEAN closest names from candidates to needle, sorted by Damerau-Levenshtein distance ascending. Names whose distance exceeds max(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 one Suggestion containing the closest alternatives. Returns an empty vec for variants we don’t enrich (everything else, including UnknownColumn/UnknownFunction whose suggestions come from upstream).
harvest_candidates 🔒
Build a Candidates set from the project cache: every project item name into items, every schema into schemas, every database into databases, and the unique non-empty cluster names referenced by project objects into clusters. Returns an empty Candidates when cache is None.
suggestions_to_data 🔒
Convert the byte-range-flavored Suggestions produced by the diagnostics formatter into LSP-shaped SuggestionData using rope to map byte offsets to line/column. Returns None when suggestions is empty so the caller can leave Diagnostic.data unset.