Expand description
Completion engine.
Routing runs through two ordered detector registries, each an
array of (source, offset, file, scopes, catalog) -> Option<Vec<Item>>
functions walked in order – first Some wins, None falls
through to the next entry. This is the only place precedence
order lives; every entry’s doc comment explains why it needs to
run where it does relative to its neighbors.
- [
PRE_PHASE_DETECTORS], run bycomplete_with_derivedbefore the cursor’s phase is even determined: fresh-name-slot suppression, JSON-path key slot, inert-span bailout, dot context (<alias>.<cursor>), grouping-sets-inner-paren, andcontexts::detect(index/trigger/policy/etc special cases the phase state machine doesn’t model). - Falling through all of those, the phase is determined –
create_index::detect/create_table::detectnarrow it when applicable, otherwisephase::Phaseviaphase::detect– and handed toroute_phase, which runs [POST_PHASE_DETECTORS] (slot-keyword shortcuts too specific for the phase match:FILTER (,WITH ORDINALITY, window frame bounds, etc), then falls through to thePhase-drivenmatchfor the “ordinary, no special case” menu per phase.
This two-registry split (rather than one flat list) mirrors the algorithm’s actual shape: stage 1 runs pre-phase, stage 2 runs post-phase, and unifying them into one list would mean reordering stage-1 checks relative to the phase-determination step in between – a real behavior change, not just reorganization.
This is what makes the menu context-aware: after SELECT * we
surface FROM, not more SELECT keywords; after a table we surface
JOIN / WHERE / GROUP BY / etc; inside ORDER BY we surface
columns + ASC/DESC; after WHERE we surface columns + expression
keywords; after a semicolon we surface top-level statement starters
only.
Functions§
- complete
- Convenience wrapper for callers with no pre-computed buffer-derived
catalog (tests, one-shot tools,
dsl-cli). Derives it fresh fromsourceviasource_tables::from_sourceon every call. Callers that invoke completion repeatedly against the same buffer (an LSP server servicing one document across many requests) should derive this catalog once and callcomplete_with_deriveddirectly instead – seeDocument::derived_catalogin dsl-server. - complete_
with_ derived - Same as
completebut takes the buffer-derived catalog (normallysource_tables::from_source(file, source)) as an explicit parameter instead of computing it internally.catalogandderivedare merged withcatalogwinning on collisions (matchessource_tables::merge’s live-wins-over-derived semantics).