fix(editor): refresh diagnostics after structure saves

This commit is contained in:
t8y2 committed 2026-08-02 19:46:44 +08:00
1 parent b75e7094c2
commit 2aeafa136c
8 files changed
+139 -1

No files matched your search

@@ -10,6 +10,7 @@ const mocks = vi.hoisted(() => ({
ensureConnected: vi.fn(),
executeTabSql: vi.fn(),
getColumns: vi.fn(),
invalidateCompletionTableCache: vi.fn(),
listIndexes: vi.fn(),
setTableMeta: vi.fn(),
updateSql: vi.fn(),
@@ -27,6 +28,7 @@ vi.mock("@/stores/connectionStore", () => ({
ensureConnected: mocks.ensureConnected,
connectionIdentifierQuote: () => undefined,
refreshObjectListTreeNode: vi.fn(),
invalidateCompletionTableCache: mocks.invalidateCompletionTableCache,
}),
}));
@@ -142,9 +144,11 @@ describe("useNavigationTargets openTableTarget", () => {
connectionId: target.connectionId,
database: target.database,
schema: target.schema,
catalog: target.catalog,
tableName: target.tableName,
});
expect(mocks.invalidateCompletionTableCache).toHaveBeenCalledWith("connection-1", "app", "users", "public", "catalog-1");
expect(mocks.getColumns).toHaveBeenCalledTimes(2);
expect(mocks.tabs.map((tab) => tab.tableMeta?.primaryKeys)).toEqual([["fresh_id"], ["fresh_id"]]);
});
@@ -9,6 +9,7 @@ const mocks = vi.hoisted(() => ({
ensureConnected: vi.fn(),
connectionIdentifierQuote: vi.fn(() => undefined),
refreshObjectListTreeNode: vi.fn(),
invalidateCompletionTableCache: vi.fn(),
},
settingsStore: {
editorSettings: {
@@ -297,7 +297,7 @@ export function useNavigationTargets(dialogs: { showFieldLineageDialog: { value:
await openTableTarget(target);
}
async function onStructureEditorSaved(reloadData: () => Promise<void>, toast: (msg: string, duration?: number) => void, context: { connectionId: string; database: string; schema?: string; tableName: string }, commentChanged?: boolean) {
async function onStructureEditorSaved(reloadData: () => Promise<void>, toast: (msg: string, duration?: number) => void, context: { connectionId: string; database: string; schema?: string; catalog?: string; tableName: string }, commentChanged?: boolean) {
if (!context.tableName) {
try {
await connectionStore.refreshObjectListTreeNode(context.connectionId, context.database, context.schema || undefined);
@@ -309,6 +309,7 @@ export function useNavigationTargets(dialogs: { showFieldLineageDialog: { value:
await connectionStore.refreshObjectListTreeNode(context.connectionId, context.database, context.schema || undefined);
} catch {}
}
connectionStore.invalidateCompletionTableCache(context.connectionId, context.database, context.tableName, context.schema, context.catalog);
queryStore.invalidateTableStructure(context.connectionId, context.database, context.schema, context.tableName);
// 结构已变更:无论是否有打开的 data tab 都必须作废共享元数据缓存,否则
// 其它 loadTableMetadata 消费者最长 30 秒拿到旧列。不带 schema/catalog