Expand description
Context-aware completion for the LSP server.
Completions are produced by a 3-phase pipeline:
Phase 1: RESOLVE CONTEXT → CompletionContext
Phase 2: GATHER CANDIDATES → Vec<CompletionCandidate>
Phase 3: FORMAT ITEMS → Vec<CompletionItem>§Phase 1: Resolve Context (resolve_context)
Builds a CompletionContext from the file URI, project cache, and prefix.
Determines the default database/schema from the file path, and resolves
the current file’s dependencies and alias map (for column completions).
All downstream logic operates on this resolved context — no further URI
parsing or project lookups needed.
§Phase 2: Gather Candidates
Four independent gatherers produce CompletionCandidates:
§Functions (gather_functions)
Sourced from super::functions::FUNCTIONS (built from mz_sql::func
registries). Only offered when dots == 0. Label is the function name,
detail is the first overload’s signature.
Kind: FUNCTION. Sort: 4_.
§Keywords (gather_keywords)
Static list from mz_sql_lexer::keywords::KEYWORDS. Only offered when
dots == 0. Label is the uppercase keyword. Kind: KEYWORD.
§Object names (gather_objects)
Dynamic per-request from project objects and external dependencies.
dots == 0: all objects with minimum qualification — bare if same-schema,schema.objectif cross-schema,db.schema.objectif cross-database. No filtering; the editor handles fuzzy matching.dots >= 1: filtered by prefix match with disambiguation. Each object is matched against candidatesschema.objectthendb.schema.object. First case-insensitive prefix match wins. Label is the remainder after the last dot in the prefix.
Sort: 1_ same-schema, 2_ cross-schema, 3_ cross-database.
§Column names (gather_columns)
Dynamic per-request from the types cache. Only offered for objects that are dependencies of the current file’s object.
- Unqualified (
dots == 0,gather_unqualified_columns): columns from all dependencies, filtered by prefix. - Qualified (
dots >= 1,gather_qualified_columns): resolves the object prefix to anObjectId(with alias map support), checks it is a dependency, and returns that object’s columns.
Sort: 0_ (before object names).
§Alias Resolution
When a qualified column prefix has a 1-part object (e.g., o.col), the
alias map is checked before falling back to default db/schema resolution.
Aliases are extracted from FROM clauses in views/materialized views.
§Phase 3: Format Items (format_candidate)
Converts each CompletionCandidate into an LSP CompletionItem with
appropriate kind, detail, and sort text.
Structs§
- Completion
Context 🔒 - Everything the completion engine needs about the cursor position and file.
- File
Object 🔒 - The current file’s resolved context for column completions.
- Prefix
Context 🔒 - Describes the dot-qualified prefix at the cursor position.
Enums§
- Completion
Candidate 🔒 - A completion candidate before final formatting.
Functions§
- complete 🔒
- Run the 3-phase completion pipeline.
- format_
candidate 🔒 - Convert a
CompletionCandidateinto an LSPCompletionItem. - format_
column_ 🔒detail - Format a column type for the completion item detail field.
- gather_
columns 🔒 - Gather column candidates from dependency objects via the types cache.
- gather_
functions 🔒 - Gather function candidates from the static function registry.
Only offered when
dots == 0(unqualified context). - gather_
keywords 🔒 - Gather keyword candidates. Only offered when
dots == 0. - gather_
objects 🔒 - Gather object candidates from project objects and external dependencies.
- gather_
qualified_ 🔒columns - Gather columns from a specific qualified object reference.
- gather_
unqualified_ 🔒columns - Gather columns from all dependencies, filtered by prefix (case-insensitive).
- object_
kind_ 🔒to_ completion_ kind - Map an
ObjectKindto the corresponding LSPCompletionItemKind. - prefix_
context 🔒 - Find the dot-qualified identifier prefix at the cursor position.
- qualify_
and_ 🔒filter - Compute the label and sort prefix for an object, filtered by the typed prefix.
- resolve_
context 🔒 - Build a
CompletionContextfrom the file URI, project cache, and prefix. - resolve_
qualified_ 🔒object - Resolve a dot-qualified object prefix to an
ObjectId.