Skip to main content

Module fallback

Module fallback 

Source
Expand description

Text-level fallback scope builder.

Used when the parser cannot make sense of the surrounding statement (which happens constantly while the user is typing, e.g. SELECT u.). We scan the raw source for FROM / JOIN clauses with regex-style passes and produce a Scope mapping aliases to table names. The result is “best effort” – nested subqueries and CTEs are not fully handled – but enough to recover useful completion in the half-written state.

Functions§

cte_columns_from_text
Like cte_names_from_text but for a single named CTE: walk the WITH ... AS (body) prefix and return the projected column names of the CTE whose name matches target (case-insensitive). The body is re-parsed as a standalone SELECT so the column names come from the projection list – including any aliases the user wrote.
cte_names_from_text
Yield the CTE names declared by a WITH [RECURSIVE] name [(cols)] AS (body), name2 AS (body2) ... prefix on src. Pure text-level scan so it still works when the parser bails on an unfinished trailing statement (the common case while the user is typing the outer FROM).
scope_from_text
Return a fallback scope, or None if no FROM / JOIN matches were found.