fix(editor): support schema-qualified table navigation

This commit is contained in:
大峰 authored and GitHub committed 2026-06-29 01:51:20 +08:00
1 parent ca30e8ff2d
commit 190b5b4ad8
4 files changed
+49 -3

No files matched your search

+16 -2
View File
@@ -164,8 +164,22 @@ export function isSqlKeyword(identifier: string): boolean {
return SQL_KEYWORDS_SET.has(identifier.toLowerCase());
}
/** Match identifier against known table names (case-insensitive). */
/** Match identifier against known table names (case-insensitive). Supports qualified identifiers like schema.table. */
export function matchTable(identifier: string, tables: Array<{ name: string; schema?: string }>): { name: string; schema?: string } | null {
const lower = identifier.toLowerCase();
return tables.find((t) => t.name.toLowerCase() === lower) ?? null;
// Direct match (simple table name)
const direct = tables.find((t) => t.name.toLowerCase() === lower);
if (direct) return direct;
// Qualified match: schema.table
const dotIndex = identifier.indexOf(".");
if (dotIndex > 0) {
const qualifier = identifier.substring(0, dotIndex).toLowerCase();
const name = identifier.substring(dotIndex + 1).toLowerCase();
const qualified = tables.find((t) => t.name.toLowerCase() === name && t.schema?.toLowerCase() === qualifier);
if (qualified) return qualified;
}
return null;
}