Expand description
Build a synthetic catalog from CREATE TABLE statements in the current file (and a few text-scanned object families) so completion / hover / validation work even offline – before the DB knows about anything, or when there is no DB connection configured at all.
Offline-mode coverage:
- Tables – AST: every CREATE TABLE in the parsed file.
- Sequences – text-scan: CREATE SEQUENCE
. - Types – text-scan: CREATE TYPE
AS ENUM/DOMAIN/(…). - Extensions – text-scan: CREATE EXTENSION [IF NOT EXISTS]
. - Functions – text-scan: CREATE [OR REPLACE] FUNCTION
. - Roles – text-scan: CREATE ROLE/USER/GROUP
; plus a fixed offline fallback set (postgres, pg_read_all_data, pg_write_all_data) so role-completion / role-hover work even in a brand-new file.
This is purely additive: the live catalog from dsl-catalog and the
source-derived one are merged at lookup time. When both define the
same object, the live catalog wins because it has richer metadata
(constraints, indexes, comments).
Functions§
- buffer_
column_ names - Text-scan fallback: harvest the column-name list from a possibly
unclosed
CREATE TABLE <name> (body. Returns names in order of appearance. Used when the SQL parser can’t produce a clean AST yet (cursor inside the body the user is still typing). - default_
offline_ roles - The conventional roles that exist in any fresh Postgres install. Returned as a Vec so callers can union them into the offline cat.
- from_
file - Build a
Catalogfrom every CREATE TABLE statement infile. Returns an empty catalog if none are found. - from_
source - Full offline-mode catalog: tables from AST + sequences / types /
extensions / functions / roles harvested from raw source text. The
scans are intentionally lenient – partial / unparseable input is
fine because the goal is “give the user something without a DB”.
sourceis the buffer text the AST infilecame from. - merge
- Merge two catalogs into one.
livewins on name collisions across every collection (tables, sequences, types, extensions, functions, roles). Derived entries fill in only where live has a gap, so a live DB connection always takes precedence over text-scanned guesses but offline use still gets the full set.