25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(editor): fetch column candidates at bare alias-dot positions
ericbyz4371a7e66646
diff --git a/apps/desktop/src/components/editor/__tests__/useQueryEditorCompletion.spec.ts b/apps/desktop/src/components/editor/__tests__/useQueryEditorCompletion.spec.tsindex e2dacc1421..9f6ae38d5a 100644--- a/apps/desktop/src/components/editor/__tests__/useQueryEditorCompletion.spec.ts+++ b/apps/desktop/src/components/editor/__tests__/useQueryEditorCompletion.spec.ts@@ -648,7 +648,8 @@ sf`,// synchronous snippet-only localResult.await provide(false);await new Promise((resolve) => setTimeout(resolve, 150));- expect(store.listCompletionColumns).toHaveBeenCalled();+ const columnFetchArgs = store.listCompletionColumns.mock.calls[0];+ expect(columnFetchArgs?.slice(0, 3)).toEqual(["connection", "demo", "users"]);} finally {vi.useFakeTimers();}@@ -710,3 +711,54 @@ describe("quoted identifier completion results (issue #12008)", () => {}}, 8000);});++describe.each([false, true])("bare alias-dot column resolution (semantic=%s)", (semanticCompletionEnabled) => {+ beforeEach(() => vi.useRealTimers());++ const aliasDotSql = "SELECT * FROM users u WHERE u.";++ it("fetches column metadata at a bare `alias.` position when nothing is cached yet (#12227 #12692)", async () => {+ const { provide, store } = createHarness({ databaseType: "postgres", dialect: "postgres", modelValue: aliasDotSql }, undefined, semanticCompletionEnabled);+ store.lookupLocalCompletionTables.mockReturnValue([{ name: "users" }]);+ store.listCompletionColumns.mockResolvedValue([+ { name: "id", table: "users" },+ { name: "email", table: "users" },+ ]);+ const result = await provide(false);+ const columnFetchArgs = store.listCompletionColumns.mock.calls[0];+ expect(columnFetchArgs?.slice(0, 3)).toEqual(["connection", "demo", "users"]);+ expect(result?.options.some((option) => option.label === "id")).toBe(true);+ });++ it("still serves cached columns synchronously at a bare `alias.` position without a remote fetch", async () => {+ const { provide, store } = createHarness({ databaseType: "postgres", dialect: "postgres", modelValue: aliasDotSql }, undefined, semanticCompletionEnabled);+ store.lookupLocalCompletionTables.mockReturnValue([{ name: "users" }]);+ store.lookupLocalCompletionColumns.mockReturnValue([{ name: "id", table: "users" }]);+ const result = await provide(false);+ expect(result?.options.some((option) => option.label === "id")).toBe(true);+ expect(store.listCompletionColumns).not.toHaveBeenCalled();+ });++ it("keeps an empty non-qualifier position from fetching metadata", async () => {+ const { provide, store } = createHarness({ databaseType: "postgres", dialect: "postgres", modelValue: "SELECT * FROM users u WHERE " }, undefined, semanticCompletionEnabled);+ store.lookupLocalCompletionTables.mockReturnValue([{ name: "users" }]);+ await provide(false);+ expect(store.listCompletionColumns).not.toHaveBeenCalled();+ });++ it("keeps schema-qualified table dots on the instant local table path", async () => {+ const { provide, store } = createHarness({ databaseType: "postgres", dialect: "postgres", modelValue: "SELECT * FROM myschema." }, undefined, semanticCompletionEnabled);+ store.lookupLocalCompletionTables.mockReturnValue([{ name: "users", schema: "myschema" }]);+ const result = await provide(false);+ expect(store.listCompletionTables).not.toHaveBeenCalled();+ expect(result?.options.some((option) => option.label === "users")).toBe(true);+ });++ it("fetches schema-qualified column metadata at a bare `schema.table.` position", async () => {+ const { provide, store } = createHarness({ databaseType: "postgres", dialect: "postgres", modelValue: "SELECT * FROM myschema.users WHERE myschema.users." }, undefined, semanticCompletionEnabled);+ store.lookupLocalCompletionTables.mockReturnValue([{ name: "users", schema: "myschema" }]);+ store.listCompletionColumns.mockResolvedValue([{ name: "id", table: "users", schema: "myschema" }]);+ const result = await provide(false);+ expect(result?.options.some((option) => option.label === "id")).toBe(true);+ });+});diff --git a/apps/desktop/src/components/editor/useQueryEditorCompletion.ts b/apps/desktop/src/components/editor/useQueryEditorCompletion.tsindex 49e5a39331..02795baf12 100644--- a/apps/desktop/src/components/editor/useQueryEditorCompletion.ts+++ b/apps/desktop/src/components/editor/useQueryEditorCompletion.ts@@ -1012,6 +1012,12 @@ export function useQueryEditorCompletion(options: QueryEditorCompletionOptions)prefix: completionContext.prefix,typedActivation,selectListColumnContext: completionContext.selectListColumnContext,+ // The cursor sits right after `alias.` with nothing typed yet: columns for the+ // referenced table are exactly what the user is asking for, so cold metadata+ // must still be fetched instead of silently yielding no candidates (#12227).+ // Table-name dots (`FROM myschema.`) share this shape but must keep their+ // instant local path, hence the tableNameCompletion exclusion.+ qualifierDot: !tableNameCompletion && !!completionContext.qualifier && !completionContext.prefix,});const shouldResolveAsyncCompletion = tableNameCompletion || shouldResolveColumnCompletion;const localResult = buildLocalSqlCompletionResult(completionContext, fullDoc, position, completionScope);diff --git a/apps/desktop/src/lib/__tests__/editor/batchColumnSelection.spec.ts b/apps/desktop/src/lib/__tests__/editor/batchColumnSelection.spec.tsindex f3619afb0e..6a1082317c 100644--- a/apps/desktop/src/lib/__tests__/editor/batchColumnSelection.spec.ts+++ b/apps/desktop/src/lib/__tests__/editor/batchColumnSelection.spec.ts@@ -170,4 +170,13 @@ describe("shouldResolveSqlColumnCompletion", () => {it("keeps empty non-SELECT column contexts from fetching metadata", () => {expect(shouldResolveSqlColumnCompletion({ suggestColumns: true, hasReferencedTables: true, prefix: "", typedActivation: false, selectListColumnContext: false })).toBe(false);});++ it("resolves a bare `alias.` position so cold metadata is fetched (#12227 #12692)", () => {+ expect(shouldResolveSqlColumnCompletion({ suggestColumns: true, hasReferencedTables: true, prefix: "", typedActivation: false, selectListColumnContext: false, qualifierDot: true })).toBe(true);+ });++ it("does not let qualifierDot override a disabled column context", () => {+ expect(shouldResolveSqlColumnCompletion({ suggestColumns: false, hasReferencedTables: true, prefix: "", typedActivation: false, selectListColumnContext: false, qualifierDot: true })).toBe(false);+ expect(shouldResolveSqlColumnCompletion({ suggestColumns: true, hasReferencedTables: false, prefix: "", typedActivation: false, selectListColumnContext: false, qualifierDot: true })).toBe(false);+ });});diff --git a/apps/desktop/src/lib/editor/batchColumnSelection.ts b/apps/desktop/src/lib/editor/batchColumnSelection.tsindex 3ae8ede094..140cd9d64c 100644--- a/apps/desktop/src/lib/editor/batchColumnSelection.ts+++ b/apps/desktop/src/lib/editor/batchColumnSelection.ts@@ -28,8 +28,8 @@ export function batchColumnSelectionColumnList(candidates: Array<string | BatchC.join("\n");}-export function shouldResolveSqlColumnCompletion(options: { suggestColumns: boolean; hasReferencedTables: boolean; prefix: string; typedActivation: boolean; selectListColumnContext: boolean }): boolean {- return options.suggestColumns && options.hasReferencedTables && (options.prefix.length > 0 || options.typedActivation || options.selectListColumnContext);+export function shouldResolveSqlColumnCompletion(options: { suggestColumns: boolean; hasReferencedTables: boolean; prefix: string; typedActivation: boolean; selectListColumnContext: boolean; qualifierDot?: boolean }): boolean {+ return options.suggestColumns && options.hasReferencedTables && (options.prefix.length > 0 || options.typedActivation || options.selectListColumnContext || !!options.qualifierDot);}export function shouldSwallowSelectStar(from: number, to: number, nextCharacter: string, replaceSelectWildcard = false): boolean {