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): ensure custom snippets pop up when preceding SQL lacks semicolon
lxk9554eb9368cc7a0
diff --git a/apps/desktop/src/components/editor/__tests__/useQueryEditorCompletion.spec.ts b/apps/desktop/src/components/editor/__tests__/useQueryEditorCompletion.spec.tsindex 9a4e5faba6..dab92eec1d 100644--- a/apps/desktop/src/components/editor/__tests__/useQueryEditorCompletion.spec.ts+++ b/apps/desktop/src/components/editor/__tests__/useQueryEditorCompletion.spec.ts@@ -556,4 +556,60 @@ describe("QueryEditor completion provider ownership", () => {expect(store.listMongoCompletionCollections).not.toHaveBeenCalled();expect(store.listRedisCompletionCommandDocs).not.toHaveBeenCalled();});++ it.each([+ [+ "multi-table join with where clause",+ `select SUM(heating_area)+from hd_self_managed_vacant v+ inner join hd_self_managed_vacant_task t on v.self_task_id = t.id+where v.hi_status = 1+ and v.\`year\` = '2026-2027'+ and v.status = 3++sf`,+ ],+ [+ "select query with limit",+ `select * from users limit 10++sf`,+ ],+ [+ "select query with where clause and trailing comment",+ `select * from users where id = 1+-- check users+sf`,+ ],+ ])("suggests custom snippets immediately when preceding SQL lacks semicolon (%s) (issue #11886)", async (_name, doc) => {+ const { settings, provide, store } = createHarness({ databaseType: "mysql", modelValue: doc });+ settings.editorSettings.snippets = [{ id: "custom-sf", label: "select * from $table", prefix: "sf", body: "select * from ${1:table_name};" }];+ // When typing (explicit: false), snippets should pop up immediately without waiting for async column fetching+ const result = await provide(false);+ expect(result).not.toBeNull();+ expect(result?.options.some((opt) => opt.type === "snippet" && (opt.displayLabel === "select * from $table" || opt.label.includes("select * from $table")))).toBe(true);+ expect(store.listCompletionColumns).not.toHaveBeenCalled();+ });++ it("does not let a local snippet hit suppress the async column fetch on on-demand-only metadata databases", async () => {+ // trino uses on-demand-only column metadata: the async fetch is never re-triggered+ // from the metadata cache, so the snippet short-circuit must not skip it. The prefix+ // sits in a column-resolution context (after WHERE) and also matches the snippet,+ // with the preceding statement left without a semicolon (issue #11886 shape).+ // This suite defaults to fake timers (the debounce never fires); switch to real+ // timers just for this case so the debounced async flow actually runs.+ vi.useRealTimers();+ try {+ const { settings, provide, store } = createHarness({ databaseType: "trino", dialect: "trino", modelValue: "select * from users limit 10\n\nselect * from users where sf" });+ settings.editorSettings.snippets = [{ id: "custom-sf", label: "select * from $table", prefix: "sf", body: "select * from ${1:table_name};" }];+ // With the guard, the typed call falls through to the debounced async flow (30ms),+ // which must request columns for the referenced table instead of settling on the+ // synchronous snippet-only localResult.+ await provide(false);+ await new Promise((resolve) => setTimeout(resolve, 150));+ expect(store.listCompletionColumns).toHaveBeenCalled();+ } finally {+ vi.useFakeTimers();+ }+ }, 8000);});diff --git a/apps/desktop/src/components/editor/useQueryEditorCompletion.ts b/apps/desktop/src/components/editor/useQueryEditorCompletion.tsindex 325d04e49a..dd66295ddc 100644--- a/apps/desktop/src/components/editor/useQueryEditorCompletion.ts+++ b/apps/desktop/src/components/editor/useQueryEditorCompletion.ts@@ -933,7 +933,12 @@ export function useQueryEditorCompletion(options: QueryEditorCompletionOptions)if (localResult) {scheduleCompletionMetadataRefresh(completionContext, fullDoc, position, completionScope);const hasLocalColumnResult = localResult.options.some((option) => option.type === "column");- if ((!explicit || typedActivation) && (!shouldResolveColumnCompletion || hasLocalColumnResult)) return localResult;+ // A local snippet hit may skip the async column fetch, but not for on-demand-only+ // column metadata (trino/presto): their fetch is never re-triggered from the+ // metadata cache, so short-circuiting here would suppress column suggestions+ // for as long as the typed prefix keeps matching the snippet prefix.+ const hasLocalSnippetResult = !usesOnDemandOnlyCompletionColumns() && localResult.options.some((option) => option.type === "snippet");+ if ((!explicit || typedActivation) && (!shouldResolveColumnCompletion || hasLocalColumnResult || hasLocalSnippetResult)) return localResult;}if ((!explicit || typedActivation) && !shouldResolveAsyncCompletion) {scheduleCompletionMetadataRefresh(completionContext, fullDoc, position, completionScope);