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(sql): rank referenced-table columns above keywords in completion (#801) (#810)
vrustxe3087e095435
diff --git a/apps/desktop/src/lib/sqlCompletion.ts b/apps/desktop/src/lib/sqlCompletion.tsindex 415b84aa9e..abb97e53b9 100644--- a/apps/desktop/src/lib/sqlCompletion.ts+++ b/apps/desktop/src/lib/sqlCompletion.ts@@ -2265,6 +2265,12 @@ function buildColumnItems(}}+ // When the query already references concrete tables (or we are after a+ // "table." qualifier / in an INSERT column list), the columns of those+ // tables are what the user is most likely picking — boost them above plain+ // keywords so they rank at the top instead of being interleaved.+ const relevanceBoost = context.referencedTables.length > 0 || !!context.qualifier || !!context.insertTable ? 2000 : 0;+return uniqueColumns.filter((column) => matchesPrefix(column.displayLabel, context.prefix)).map((column) => {@@ -2275,7 +2281,7 @@ function buildColumnItems(detail: buildColumnDetail(column),info: buildColumnInfo(column),apply: buildColumnApply(column, context, dialect),- boost: computeBoost(column.displayLabel, context.prefix) + keyBoost,+ boost: computeBoost(column.displayLabel, context.prefix) + keyBoost + relevanceBoost,};}).sort(compareCompletionItems);diff --git a/packages/app-tests/sqlCompletion.test.ts b/packages/app-tests/sqlCompletion.test.tsindex a5cb826eb5..dd9da4b940 100644--- a/packages/app-tests/sqlCompletion.test.ts+++ b/packages/app-tests/sqlCompletion.test.ts@@ -838,6 +838,21 @@ test("key columns get priority boost in column suggestions", () => {assert.ok(idItem.boost > nameItem.boost, "id column should have higher boost than name");});+test("referenced-table columns rank above keywords (#801)", () => {+ const items = buildSqlCompletionItems("select from public.users u", "select ".length, {+ tables,+ columnsByTable,+ });+ const column = items.find((item) => item.type === "column");+ assert.ok(column, "should suggest columns when a table is referenced");+ assert.ok(column.boost >= 2000, "referenced-table columns should be boosted above plain keywords");+ const columnIdx = items.findIndex((item) => item.type === "column");+ const keywordIdx = items.findIndex((item) => item.type === "keyword");+ if (keywordIdx >= 0) {+ assert.ok(columnIdx < keywordIdx, "columns should appear before keywords in a referenced-table context");+ }+});+// --- Schema name completion ---test("suggests schema names alongside tables in FROM context", () => {