fix(editor): support qualified table navigation

This commit is contained in:
大峰 authored and GitHub committed 2026-07-02 22:00:51 +08:00
1 parent 82e9df1853
commit 9083dc0e53
3 files changed
+149 -53

No files matched your search

@@ -31,7 +31,7 @@ import {
} from "@/lib/sqlCompletion";
import { buildElasticsearchCompletionItemsFromContext, getElasticsearchCompletionContext, getElasticsearchCompletionResultValidFor, shouldAutoOpenElasticsearchCompletion, type ElasticsearchCompletionItem } from "@/lib/elasticsearchCompletion";
import { buildMongoCompletionItemsFromContext, getMongoCompletionContext, getMongoCompletionResultValidFor, shouldAutoOpenMongoCompletion, type MongoCompletionItem } from "@/lib/mongoCompletion";
import { extractIdentifierAt, isSqlKeyword, matchTable } from "@/lib/sqlNavigation";
import { extractIdentifierAt, isSqlKeyword, matchTable, splitQualifiedIdentifier } from "@/lib/sqlNavigation";
import { lineColumnToOffset, parseSqlErrorLocation } from "@/lib/sqlDiagnostics";
import {
DBX_TABLE_REFERENCE_MIME,
@@ -2432,11 +2432,15 @@ onMounted(async () => {
event.preventDefault();
setTimeout(async () => {
try {
const identifierParts = splitQualifiedIdentifier(identifier);
const tableLookupFilter = identifierParts[identifierParts.length - 1] ?? identifier;
// Ensure table cache is populated
if (cachedTables.length === 0) {
// Some metadata providers only accept table-name masks, not schema.table masks.
cachedTables = usesLocalOnlyCompletionMetadata()
? connectionStore.lookupLocalCompletionTables(props.connectionId!, props.database!, identifier, MAX_COMPLETION_TABLES, props.schema)
: await connectionStore.listCompletionTables(props.connectionId!, props.database!, identifier, MAX_COMPLETION_TABLES, props.schema);
? connectionStore.lookupLocalCompletionTables(props.connectionId!, props.database!, tableLookupFilter, MAX_COMPLETION_TABLES, props.schema)
: await connectionStore.listCompletionTables(props.connectionId!, props.database!, tableLookupFilter, MAX_COMPLETION_TABLES, props.schema);
}
// 1. Check if it's a table name
@@ -2459,20 +2463,14 @@ onMounted(async () => {
});
// Check if identifier has a qualifier (e.g., c.card_name or schema.table)
const qualifierMatch = /^(.+)\.(.+)$/.exec(identifier);
const qualifier = qualifierMatch ? qualifierMatch[1] : null;
const qualifier = identifierParts.length >= 2 ? identifierParts[identifierParts.length - 2] : null;
// 2b. Qualified identifier (schema.table): check against SQL-parsed referenced tables
if (qualifierMatch) {
const qQualifier = qualifierMatch[1].toLowerCase();
const qTableName = qualifierMatch[2].toLowerCase();
const matchedRef = referencedTables.find((rt) => rt.name.toLowerCase() === qTableName && rt.schema?.toLowerCase() === qQualifier);
if (matchedRef) {
emit("clickTable", matchedRef.schema ? `${matchedRef.schema}.${matchedRef.name}` : matchedRef.name);
return;
}
const matchedRef = matchTable(identifier, referencedTables);
if (matchedRef) {
emit("clickTable", matchedRef.schema ? `${matchedRef.schema}.${matchedRef.name}` : matchedRef.name);
return;
}
const colName = qualifierMatch ? qualifierMatch[2] : identifier;
const colName = identifierParts[identifierParts.length - 1] ?? identifier;
const colLower = colName.toLowerCase();
if (referencedTables.length === 0) {