mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-31 08:23:34 +00:00
feat: support schema-qualified table completion in SQL editor
When typing `schema.` in the SQL editor for schema-aware databases (PostgreSQL, GaussDB, etc.), auto-complete now suggests tables from that schema. Falls back to schema lookup when the qualifier doesn't match any table name. Closes #239
This commit is contained in:
@@ -128,7 +128,7 @@ async function provideSqlCompletions(currentState: import("@codemirror/state").E
|
||||
const fullDoc = currentState.doc.toString();
|
||||
const completionContext = getSqlCompletionContext(fullDoc, position);
|
||||
const shouldLoadTables = completionContext.suggestTables || !!completionContext.qualifier;
|
||||
const tables = shouldLoadTables
|
||||
let tables = shouldLoadTables
|
||||
? await connectionStore.listCompletionTables(
|
||||
props.connectionId,
|
||||
props.database,
|
||||
@@ -137,6 +137,22 @@ async function provideSqlCompletions(currentState: import("@codemirror/state").E
|
||||
)
|
||||
: cachedTables;
|
||||
|
||||
// If qualifier didn't match any table names, try it as a schema name
|
||||
let qualifierIsSchema = false;
|
||||
if (completionContext.qualifier && completionContext.suggestTables && tables.length === 0) {
|
||||
const schemaTables = await connectionStore.listCompletionTables(
|
||||
props.connectionId,
|
||||
props.database,
|
||||
completionContext.prefix,
|
||||
MAX_COMPLETION_TABLES,
|
||||
completionContext.qualifier,
|
||||
);
|
||||
if (schemaTables.length > 0) {
|
||||
tables = schemaTables;
|
||||
qualifierIsSchema = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Collect referenced tables — enrich with schema from filtered table lookup
|
||||
let refs = completionContext.referencedTables.map((rt) => {
|
||||
// If no schema, look it up in the cached tables
|
||||
@@ -200,7 +216,11 @@ async function provideSqlCompletions(currentState: import("@codemirror/state").E
|
||||
}
|
||||
}
|
||||
|
||||
const items = buildSqlCompletionItemsFromContext(completionContext, {
|
||||
const effectiveContext = qualifierIsSchema
|
||||
? { ...completionContext, qualifier: undefined, suggestTables: true, suggestColumns: false }
|
||||
: completionContext;
|
||||
|
||||
const items = buildSqlCompletionItemsFromContext(effectiveContext, {
|
||||
tables,
|
||||
columnsByTable,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user