Skip to main content

Module source_tables

Module source_tables 

Source
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 Catalog from every CREATE TABLE statement in file. 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”. source is the buffer text the AST in file came from.
merge
Merge two catalogs into one. live wins 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.