mirror of
https://github.com/t8y2/dbx.git
synced 2026-11-01 08:26:35 +00:00
fix(sqlserver): avoid false unknown column diagnostics
This commit is contained in:
@@ -393,6 +393,7 @@ async function ensureColumnsForTable(table: { name: string; schema?: string | nu
|
||||
table.name,
|
||||
table.schema ?? undefined,
|
||||
);
|
||||
if (columns.length === 0) return;
|
||||
cachedColumnsByTable.set(cacheKey, columns);
|
||||
}
|
||||
|
||||
@@ -754,10 +755,12 @@ async function provideSqlCompletions(
|
||||
completionContext.insertSchema,
|
||||
);
|
||||
if (epoch !== completionEpoch) return null;
|
||||
const insertKey = completionContext.insertSchema
|
||||
? `${completionContext.insertSchema}.${completionContext.insertTable}`
|
||||
: completionContext.insertTable;
|
||||
insertColumnsByTable.set(insertKey, insertCols);
|
||||
if (insertCols.length > 0) {
|
||||
const insertKey = completionContext.insertSchema
|
||||
? `${completionContext.insertSchema}.${completionContext.insertTable}`
|
||||
: completionContext.insertTable;
|
||||
insertColumnsByTable.set(insertKey, insertCols);
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
@@ -865,6 +868,7 @@ async function provideSqlCompletions(
|
||||
refTable.schema,
|
||||
);
|
||||
if (epoch !== completionEpoch) return;
|
||||
if (columns.length === 0) return;
|
||||
cachedColumnsByTable.set(cacheKey, columns);
|
||||
} catch (e) {
|
||||
console.error(`[DBX] Failed to load columns for ${cacheKey}:`, e);
|
||||
|
||||
@@ -119,7 +119,9 @@ function columnsForTable(
|
||||
const keys = table.schema ? [`${table.schema}.${table.name}`, table.name] : [table.name];
|
||||
for (const key of keys) {
|
||||
const columns = columnsByTable.get(key) ?? columnsByTable.get(normalizeName(key));
|
||||
if (columns) return columns;
|
||||
// Empty metadata usually means the upstream schema lookup was inconclusive,
|
||||
// so avoid surfacing a false "unknown column" warning.
|
||||
if (columns && columns.length > 0) return columns;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1419,6 +1419,9 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
table: string,
|
||||
schema?: string,
|
||||
): Promise<SqlCompletionColumn[]> {
|
||||
if (isSchemaAwareDatabase(connectionId) && !schema) {
|
||||
return [];
|
||||
}
|
||||
const cacheKey = `${connectionId}:${database}:${schema || ""}:${table}`;
|
||||
if (!completionColumnsCache.value[cacheKey]) {
|
||||
await ensureConnected(connectionId);
|
||||
|
||||
Reference in New Issue
Block a user