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): explain why Format SQL did nothing
HARRISONb612dec12c11
diff --git a/apps/desktop/src/components/editor/QueryEditor.vue b/apps/desktop/src/components/editor/QueryEditor.vueindex 3a22d2eae3..f55c7c9838 100644--- a/apps/desktop/src/components/editor/QueryEditor.vue+++ b/apps/desktop/src/components/editor/QueryEditor.vue@@ -69,7 +69,7 @@ import { executableStatementRangeAtCursor, executableStatementRangeCacheForDoc,import { looksLikeDmlStatement } from "@/lib/sql/dmlChangePreview";-import { canFormatSqlForDatabaseType, formatSqlForEditing, compressSqlText } from "@/lib/sql/sqlFormatter";+import { canFormatSqlForDatabaseType, formatSqlText, compressSqlText } from "@/lib/sql/sqlFormatter";import { detectAndFormatStructured } from "@/lib/sql/autoFormat";import { restoreSqlFromSourcePaste } from "@/lib/sql/sqlSourcePaste";import { enabledSqlParameterSyntaxes, resolveSqlVariableSyntaxToggles } from "@/lib/sql/sqlVariableSyntax";@@ -1735,7 +1735,12 @@ async function formatCurrentSql() {return;} else {formattedAsSql = true;- formatted = await formatSqlForEditing(source, formatDialect, settingsStore.editorSettings.sqlFormatter);+ // The explicit Format command has to say why it did nothing:+ // `formatSqlForEditing` returns unparseable input unchanged (the right+ // contract for format-on-save, which must never fail), which turned+ // this command into a silent no-op. A thrown error reaches the+ // `formatError` toast below.+ formatted = await formatSqlText(source, formatDialect, settingsStore.editorSettings.sqlFormatter);}}}diff --git a/apps/desktop/src/components/editor/__tests__/QueryEditor.formatCompressRequestReplay.spec.ts b/apps/desktop/src/components/editor/__tests__/QueryEditor.formatCompressRequestReplay.spec.tsindex bf9899615b..68cc5c5e1b 100644--- a/apps/desktop/src/components/editor/__tests__/QueryEditor.formatCompressRequestReplay.spec.ts+++ b/apps/desktop/src/components/editor/__tests__/QueryEditor.formatCompressRequestReplay.spec.ts@@ -46,6 +46,7 @@ function mountEditor(initial: { modelValue: string; tabId: string; databaseType?compressRequestId: initial.compressRequestId,});const emits: string[] = [];+ const formatErrors: string[] = [];const root = defineComponent({setup: () => () =>h(QueryEditor, {@@ -63,6 +64,9 @@ function mountEditor(initial: { modelValue: string; tabId: string; databaseType?// store, so the modelValue prop follows the editor document.state.modelValue = value;},+ onFormatError: (message: string) => {+ formatErrors.push(message);+ },}),});const host = document.createElement("div");@@ -75,7 +79,7 @@ function mountEditor(initial: { modelValue: string; tabId: string; databaseType?app.unmount();host.remove();});- return { state, emits, host, unmount: () => app.unmount() };+ return { state, emits, formatErrors, host, unmount: () => app.unmount() };}async function waitForEditor(host: HTMLElement) {@@ -180,19 +184,22 @@ describe("QueryEditor format/compress request replay", () => {expect(undo(editorView)).toBe(false);});- it("does not move the caret or dispatch a change when a parse failure returns the source", async () => {+ it("reports the parse failure instead of silently formatting nothing", async () => {const source = "SELECT 1 .";- const { state, emits, host } = mountEditor({ modelValue: source, tabId: "tab-a" });+ const { state, emits, formatErrors, host } = mountEditor({ modelValue: source, tabId: "tab-a" });await waitForEditor(host);const editorView = EditorView.findFromDOM(host.querySelector(".cm-editor") as HTMLElement)!;const caret = source.indexOf("1");editorView.dispatch({ selection: { anchor: caret } });state.formatRequestId = 5;- await settle();- await settle();+ // The formatter cannot parse the statement, so the command must say so+ // rather than return the source and leave the editor looking untouched.+ await vi.waitFor(() => expect(formatErrors).toHaveLength(1), WAIT);+ expect(formatErrors[0]).toContain("Parse error");expect(emits).toEqual([]);+ expect(editorView.state.doc.toString()).toBe(source);expect(editorView.state.selection.main.head).toBe(caret);});