Skip to main content

Module completion

Module completion 

Source
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.object if cross-schema, db.schema.object if cross-database. No filtering; the editor handles fuzzy matching.
  • dots >= 1: filtered by prefix match with disambiguation. Each object is matched against candidates schema.object then db.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.

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§

CompletionContext 🔒
Everything the completion engine needs about the cursor position and file.
FileObject 🔒
The current file’s resolved context for column completions.
PrefixContext 🔒
Describes the dot-qualified prefix at the cursor position.

Enums§

CompletionCandidate 🔒
A completion candidate before final formatting.

Functions§

complete 🔒
Run the 3-phase completion pipeline.
format_candidate 🔒
Convert a CompletionCandidate into an LSP CompletionItem.
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 ObjectKind to the corresponding LSP CompletionItemKind.
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 CompletionContext from the file URI, project cache, and prefix.
resolve_qualified_object 🔒
Resolve a dot-qualified object prefix to an ObjectId.