Skip to content

armgit / dbx

Public Imported from GitHub
0

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。

fix(editor): continue completion after selecting schemas

zipgd794bbe768b8
diff --git a/apps/desktop/src/components/editor/QueryEditor.vue b/apps/desktop/src/components/editor/QueryEditor.vue
index 56e80016d3..ac83862217 100644
--- a/apps/desktop/src/components/editor/QueryEditor.vue
+++ b/apps/desktop/src/components/editor/QueryEditor.vue
@@ -31,6 +31,7 @@ import {
isSqlLikeCompletionStatement,
recordCompletionSelection,
shouldAutoOpenSqlCompletion,
+ shouldChainSqlCompletionAfterAccept,
extractCteDefinitions,
} from "@/lib/sql/sqlCompletion";
import { sqlCompletionContextFromSemantic } from "@/lib/sql/semantic/completion";
@@ -1762,8 +1763,8 @@ function isTypedCompletionActivation(explicit: boolean) {
return explicit && typedCompletionActivationUntil >= Date.now();
}
-function markCompletionAccepted() {
- suppressNextSqlCompletionAutoStartUntil = Date.now() + 750;
+function markCompletionAccepted(item: QueryCompletionItem) {
+ suppressNextSqlCompletionAutoStartUntil = shouldChainSqlCompletionAfterAccept(item) ? 0 : Date.now() + 750;
completionEpoch++;
}
@@ -1820,7 +1821,7 @@ function completionOptionForItem(item: QueryCompletionItem) {
...completion,
apply(view: EditorViewType, completionItem: unknown, from: number, to: number) {
record();
- markCompletionAccepted();
+ markCompletionAccepted(item);
if (typeof originalApply === "function") {
originalApply(view, completionItem as never, from, to);
} else {
@@ -1841,7 +1842,7 @@ function completionOptionForItem(item: QueryCompletionItem) {
boost: item.boost,
apply(view: EditorViewType, _completionItem: unknown, from: number, to: number) {
record();
- markCompletionAccepted();
+ markCompletionAccepted(item);
const insert = item.apply ?? item.label;
if (codeMirrorInsertCompletionText) {
view.dispatch(codeMirrorInsertCompletionText(view.state, insert, from, to));
diff --git a/apps/desktop/src/lib/sql/sqlCompletion.ts b/apps/desktop/src/lib/sql/sqlCompletion.ts
index ddaf87e755..3212bf27ca 100644
--- a/apps/desktop/src/lib/sql/sqlCompletion.ts
+++ b/apps/desktop/src/lib/sql/sqlCompletion.ts
@@ -1121,6 +1121,10 @@ export interface SqlCompletionItem {
exactMatch?: boolean;
}
+export function shouldChainSqlCompletionAfterAccept(item: { type?: string; apply?: string }): boolean {
+ return item.type === "schema" && item.apply?.endsWith(".") === true;
+}
+
export type SqlKeywordCase = "preserve" | "upper" | "lower";
export interface SqlCompletionReferencedTable {
diff --git a/packages/app-tests/sqlCompletion.test.ts b/packages/app-tests/sqlCompletion.test.ts
index 8b0d1df41c..f479f48a45 100644
--- a/packages/app-tests/sqlCompletion.test.ts
+++ b/packages/app-tests/sqlCompletion.test.ts
@@ -10,6 +10,7 @@ import {
extractCteDefinitions,
getSqlCompletionContext,
recordCompletionSelection,
+ shouldChainSqlCompletionAfterAccept,
type SqlCompletionColumn,
type SqlCompletionForeignKey,
type SqlCompletionObject,
@@ -623,6 +624,16 @@ test("keeps schema-qualified FROM object input in table suggestion mode", () =>
);
});
+test("keeps an accepted schema with trailing dot in table suggestion mode", () => {
+ const sql = "SELECT *\nFROM DBX_TEST.";
+ const context = getSqlCompletionContext(sql, sql.length);
+
+ assert.equal(context.qualifier, "DBX_TEST");
+ assert.equal(context.prefix, "");
+ assert.equal(context.suggestTables, true);
+ assert.equal(context.exclusiveTableSuggestions, true);
+});
+
test("keeps database-qualified FROM input in table suggestion mode", () => {
const sql = "select * from other_db.or";
const context = getSqlCompletionContext(sql, sql.length);
@@ -1827,6 +1838,8 @@ test("schema items include apply value with trailing dot", () => {
const schemaItems = items.filter((item) => item.type === "schema");
assert.equal(schemaItems.length, 1);
assert.equal(schemaItems[0]?.apply, "public.");
+ assert.equal(shouldChainSqlCompletionAfterAccept(schemaItems[0]!), true);
+ assert.equal(shouldChainSqlCompletionAfterAccept({ type: "table", apply: "users" }), false);
});
// --- Quoted identifier fix ---