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
feat(completion): render icons for sequence and variable items
弈秋8381fa4f44c3
diff --git a/apps/desktop/src/lib/__tests__/editorThemes.spec.ts b/apps/desktop/src/lib/__tests__/editorThemes.spec.tsindex c5fb876cc2..ff105d2529 100644--- a/apps/desktop/src/lib/__tests__/editorThemes.spec.ts+++ b/apps/desktop/src/lib/__tests__/editorThemes.spec.ts@@ -264,6 +264,18 @@ describe("SQL completion theme", () => {});expect(rules[".cm-completionIcon"]).toMatchObject({ width: "15px", height: "15px", overflow: "hidden" });});++ // #12099: sequence completions were typed "variable" but no icon mask was+ // defined for that kind, so the menu rendered a blank icon slot.+ it("defines completion icon masks for sequence and variable kinds", () => {+ const rules = buildSqlCompletionThemeRules();++ for (const key of [".cm-completionIcon-sequence", ".cm-completionIcon-variable"]) {+ expect(rules[key]).toMatchObject({+ "--dbx-completion-icon-mask": expect.stringContaining("data:image/svg+xml"),+ });+ }+ });});describe("SQL builtin highlight tag", () => {diff --git a/apps/desktop/src/lib/__tests__/sql/sqlCompletion.context.spec.ts b/apps/desktop/src/lib/__tests__/sql/sqlCompletion.context.spec.tsindex ec7cb0f2e3..ce800c8bbe 100644--- a/apps/desktop/src/lib/__tests__/sql/sqlCompletion.context.spec.ts+++ b/apps/desktop/src/lib/__tests__/sql/sqlCompletion.context.spec.ts@@ -533,7 +533,7 @@ describe("PostgreSQL sequence literal completion", () => {expect.arrayContaining([expect.objectContaining({label: "ORDER_SEQ",- type: "variable",+ type: "sequence",detail: "sequence in APP",apply: "ORDER_SEQ",}),@@ -552,7 +552,7 @@ describe("PostgreSQL sequence literal completion", () => {expect.arrayContaining([expect.objectContaining({label: "ORDER_SEQ",- type: "variable",+ type: "sequence",detail: "sequence in APP",apply: "APP.ORDER_SEQ",}),@@ -574,7 +574,7 @@ describe("PostgreSQL sequence literal completion", () => {expect.arrayContaining([expect.objectContaining({label: "ORDER_SEQ",- type: "variable",+ type: "sequence",apply: "ORDER_SEQ",}),]),@@ -690,7 +690,7 @@ describe("PostgreSQL sequence literal completion", () => {expect.arrayContaining([expect.objectContaining({label: "ORDER_SEQ",- type: "variable",+ type: "sequence",detail: "sequence in APP",apply: "ORDER_SEQ",}),@@ -709,7 +709,7 @@ describe("PostgreSQL sequence literal completion", () => {expect.arrayContaining([expect.objectContaining({label: "ORDER_SEQ",- type: "variable",+ type: "sequence",detail: "sequence in APP",apply: "APP.ORDER_SEQ",}),@@ -731,7 +731,7 @@ describe("PostgreSQL sequence literal completion", () => {expect.arrayContaining([expect.objectContaining({label: "ORDER_SEQ",- type: "variable",+ type: "sequence",apply: "ORDER_SEQ",}),]),diff --git a/apps/desktop/src/lib/editor/editorThemes.ts b/apps/desktop/src/lib/editor/editorThemes.tsindex 28a3c2eed4..f3c35d7bec 100644--- a/apps/desktop/src/lib/editor/editorThemes.ts+++ b/apps/desktop/src/lib/editor/editorThemes.ts@@ -643,6 +643,21 @@ const DATABASE_LINK_ICON: LucideIconNode = [const SCHEMA_ICON: LucideIconNode = [["path", { d: "M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2v11z" }]];+const SEQUENCE_ICON: LucideIconNode = [+ ["path", { d: "M8 5h13" }],+ ["path", { d: "M13 12h8" }],+ ["path", { d: "M13 19h8" }],+ ["path", { d: "M3 10a2 2 0 0 0 2 2h3" }],+ ["path", { d: "M3 5v12a2 2 0 0 0 2 2h3" }],+];++const VARIABLE_ICON: LucideIconNode = [+ ["path", { d: "M8 21s-4-3-4-9 4-9 4-9" }],+ ["path", { d: "M16 3s4 3 4 9-4 9-4 9" }],+ ["line", { x1: "15", x2: "9", y1: "9", y2: "15" }],+ ["line", { x1: "9", x2: "15", y1: "9", y2: "15" }],+];+function encodeSvgIcon(iconNode: LucideIconNode): string {const body = iconNode.map(@@ -1125,6 +1140,16 @@ export function buildSqlCompletionThemeRules(): CodeMirrorStyleSpec {color: colorMixValue("var(--amber-500, #f59e0b)", "color-mix(in oklch, var(--amber-500, #f59e0b) 92%, var(--popover-foreground))"),...lucideCompletionIconMask(SCHEMA_ICON),},+ // Sequences previously reused "variable" without any icon mask, which+ // rendered a blank slot (#12099). Match the sidebar's emerald ListTree.+ ".cm-completionIcon-sequence": {+ color: colorMixValue("var(--emerald-500, #10b981)", "color-mix(in oklch, var(--emerald-500, #10b981) 92%, var(--popover-foreground))"),+ ...lucideCompletionIconMask(SEQUENCE_ICON),+ },+ ".cm-completionIcon-variable": {+ color: colorMixValue("var(--rose-500, #f43f5e)", "color-mix(in oklch, var(--rose-500, #f43f5e) 92%, var(--popover-foreground))"),+ ...lucideCompletionIconMask(VARIABLE_ICON),+ },// Reuse the table glyph for aliases instead of CodeMirror's default text// icon, which is rendered as a solid black square in some themes.".cm-completionIcon-text": {diff --git a/apps/desktop/src/lib/editor/sqlCompletionInsertion.ts b/apps/desktop/src/lib/editor/sqlCompletionInsertion.tsindex 79acd48d9c..cfaa1a09bc 100644--- a/apps/desktop/src/lib/editor/sqlCompletionInsertion.ts+++ b/apps/desktop/src/lib/editor/sqlCompletionInsertion.ts@@ -1,4 +1,4 @@-export type SqlCompletionItemType = "keyword" | "table" | "column" | "snippet" | "function" | "schema" | "variable" | "property" | "text";+export type SqlCompletionItemType = "keyword" | "table" | "column" | "snippet" | "function" | "schema" | "variable" | "sequence" | "property" | "text";// `;` is deliberately absent: a statement terminator is never glued to the token// in front of it, and accepting `BETWEEN` before an existing `;` used to insert@@ -6,7 +6,7 @@ export type SqlCompletionItemType = "keyword" | "table" | "column" | "snippet" |const COMPLETION_SPACE_BLOCKING_CHARACTERS = new Set([",", ":", ")", "]", "}", "'", '"']);export function appendSqlCompletionSpace(insertText: string, options: { enabled: boolean; itemType: SqlCompletionItemType; nextCharacter?: string }): string {- if (!options.enabled || options.itemType === "property" || options.itemType === "text" || options.itemType === "schema" || options.itemType === "variable" || options.itemType === "snippet" || options.itemType === "function") return insertText;+ if (!options.enabled || options.itemType === "property" || options.itemType === "text" || options.itemType === "schema" || options.itemType === "variable" || options.itemType === "sequence" || options.itemType === "snippet" || options.itemType === "function") return insertText;if (!insertText || /\s$/.test(insertText) || insertText.endsWith(".")) return insertText;const nextCharacter = options.nextCharacter ?? "";diff --git a/apps/desktop/src/lib/sql/sqlCompletion.ts b/apps/desktop/src/lib/sql/sqlCompletion.tsindex 7942e05cc6..1d62f23edc 100644--- a/apps/desktop/src/lib/sql/sqlCompletion.ts+++ b/apps/desktop/src/lib/sql/sqlCompletion.ts@@ -1526,7 +1526,7 @@ export type SqlCompletionClosingQuote = '"' | "'" | "`" | "]";export interface SqlCompletionItem {label: string;filterText?: string;- type: "keyword" | "table" | "column" | "snippet" | "function" | "schema" | "variable" | "text";+ type: "keyword" | "table" | "column" | "snippet" | "function" | "schema" | "variable" | "sequence" | "text";detail?: string;info?: string | ((completion: Completion) => CompletionInfo | Promise<CompletionInfo>);apply?: string;@@ -2069,7 +2069,7 @@ export function buildPostgresSequenceLiteralCompletionItems(context: PostgresSeqreturn {label: object.name,filterText: context.nameQuoted ? identifier.slice(0, -1) : escapePostgresSequenceLiteralIdentifier(object.name),- type: "variable" as const,+ type: "sequence" as const,detail: object.schema ? `sequence in ${object.schema}` : "sequence",info: object.comment?.trim() || undefined,apply: identifier,@@ -4852,7 +4852,7 @@ function buildObjectItems(context: SqlCompletionContext, objects: SqlCompletionOconst baseDedupeKey = object.applyName || (isOracleCompletionDatabase(databaseType) && object.schema) ? applyName : undefined;return {label: object.name,- type: object.type === "sequence" ? ("variable" as const) : ("function" as const),+ type: object.type === "sequence" ? ("sequence" as const) : ("function" as const),detail,info: buildRoutineInfo(object),apply: object.type === "trigger" || object.type === "package" || object.type === "sequence" || (databaseType === "oceanbase-oracle" && object.signature == null) ? applyName : buildRoutineApply(applyName, object.signature, includeParams),@@ -6609,7 +6609,9 @@ function dedupeAndSort(items: SqlCompletionItem[]): SqlCompletionItem[] {}function compareCompletionItems(left: SqlCompletionItem, right: SqlCompletionItem): number {- if ((left.type === "variable") !== (right.type === "variable")) return left.type === "variable" ? -1 : 1;+ const leftSurfacesFirst = left.type === "variable" || left.type === "sequence";+ const rightSurfacesFirst = right.type === "variable" || right.type === "sequence";+ if (leftSurfacesFirst !== rightSurfacesFirst) return leftSurfacesFirst ? -1 : 1;if (!left.exactMatch !== !right.exactMatch) return left.exactMatch ? -1 : 1;const leftBonus = getHistoryBoost(left.label, left.type);const rightBonus = getHistoryBoost(right.label, right.type);@@ -6626,6 +6628,8 @@ function getTypePriorityBoost(type: SqlCompletionItem["type"]): number {return 120;case "variable":return 220;+ case "sequence":+ return 220;case "text":return 220;case "function":