Skip to content

Commit 58a911a

Browse files
committed
eliminiate pg catalog functions unless the prefix is typed
1 parent a1f21ad commit 58a911a

3 files changed

Lines changed: 24 additions & 6 deletions

File tree

src/autocomplete/provider.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ export function createAutocompleteProvider(
242242
}
243243
}
244244

245+
const partialPrefix =
246+
isMidWord && tokensBefore.length > 0
247+
? tokensBefore[tokensBefore.length - 1].image.toLowerCase()
248+
: ""
249+
245250
// If parser returned valid next tokens, use grammar-based classification
246251
if (nextTokenTypes.length > 0) {
247252
const suggestions = buildSuggestions(
@@ -256,6 +261,7 @@ export function createAutocompleteProvider(
256261
includeWindowFunctions: suggestWindowFunctions,
257262
includeTableValuedFunctions: suggestTableValuedFunctions,
258263
isMidWord,
264+
partialPrefix,
259265
},
260266
)
261267
if (suggestTables) {

src/autocomplete/suggestion-builder.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ export function buildSuggestions(
120120
includeWindowFunctions?: boolean
121121
includeTableValuedFunctions?: boolean
122122
isMidWord?: boolean
123+
/** Lowercased text the user is currently typing (the mid-word token). */
124+
partialPrefix?: string
123125
},
124126
): Suggestion[] {
125127
const suggestions: Suggestion[] = []
@@ -136,6 +138,10 @@ export function buildSuggestions(
136138
const includeTableValuedFunctions =
137139
options?.includeTableValuedFunctions ?? false
138140
const isMidWord = options?.isMidWord ?? false
141+
const partialPrefix = options?.partialPrefix ?? ""
142+
143+
const showPgCatalog = partialPrefix.startsWith("pg")
144+
const isPgCatalogName = (name: string): boolean => name.startsWith("pg_")
139145

140146
// Detect join context: when "Join" is a valid next token, join prefix
141147
// keywords (LEFT, RIGHT, ASOF, etc.) should be suggested as compounds.
@@ -316,6 +322,7 @@ export function buildSuggestions(
316322
if (isMidWord) {
317323
const emitFn = (name: string) => {
318324
if (seenKeywords.has(name.toUpperCase())) return
325+
if (isPgCatalogName(name) && !showPgCatalog) return
319326
suggestions.push({
320327
label: name,
321328
kind: SuggestionKind.Function,

src/grammar/functions.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@
55
// and verified against source code in questdb/ and questdb-enterprise/.
66
//
77
// Categories used for context-aware autocomplete:
8-
// - scalarFunctions — single-row functions (FROM functions() type=STANDARD)
9-
// - aggregateFunctions — collapse rows (type=GROUP_BY); also valid as windows
10-
// - windowFunctions — pure ranking/offset (type=WINDOW, no GROUP_BY overload)
8+
// - scalarFunctions — single-row functions (FROM functions() type=STANDARD)
9+
// - aggregateFunctions — collapse rows (type=GROUP_BY); also valid as windows
10+
// - windowFunctions — pure ranking/offset (type=WINDOW, no GROUP_BY overload)
1111
// - tableValuedFunctions — return rows (type=CURSOR, or STANDARD that succeeds
12-
// in `SELECT * FROM <name>()` — meta pseudo-tables like `materialized_views`)
12+
// in `SELECT * FROM <name>()` — meta pseudo-tables like `materialized_views`,
13+
// plus PostgreSQL-compat catalog entries like `pg_class` and `pg_catalog.*`.
14+
// The pg_-prefixed entries are gated at emission time by the suggestion-
15+
// builder: they only surface when the user has typed a "pg" prefix, so the
16+
// letter "p" alone doesn't bury real schema results in JOIN positions.
17+
// `information_schema.*` is NOT gated — those names are SQL-standard.
1318
//
1419
// Removed from earlier flat list: 17 entries absent from QuestDB runtime AND
1520
// docs (e.g. `array_agg`, `lcase`, `len`, `nvl`, `headers`, `show`,
@@ -181,7 +186,6 @@ export const scalarFunctions: string[] = [
181186
"sysdate",
182187
"systimestamp",
183188
"systimestamp_ns",
184-
"table_columns",
185189
"tan",
186190
"timestamp_ceil",
187191
"timestamp_floor",
@@ -210,7 +214,6 @@ export const scalarFunctions: string[] = [
210214
"typeOf",
211215
"upper",
212216
"version",
213-
"wal_transactions",
214217
"week_of_year",
215218
"within",
216219
"within_box",
@@ -332,11 +335,13 @@ export const tableValuedFunctions: string[] = [
332335
"pg_proc",
333336
"query_activity",
334337
"reader_pool",
338+
"table_columns",
335339
"table_storage",
336340
"table_writer_metrics",
337341
"tables",
338342
"views",
339343
"wal_tables",
344+
"wal_transactions",
340345
"writer_pool",
341346
]
342347

0 commit comments

Comments
 (0)