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_textbut for a single named CTE: walk theWITH ... AS (body)prefix and return the projected column names of the CTE whose name matchestarget(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 onsrc. 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.