Skip to content

Commit b9b144c

Browse files
committed
refactor(sql): migrate SQL editor from Monaco to CodeMirror 6
Replace Monaco with @uiw/react-codemirror + @codemirror/lang-sql for the SQL workspace editor. Schema-aware, alias-aware completion driven by the catalog tree; catalog arrow notation (catalog=>table) suggestions; Tab to accept, Mod-Enter to run, Shift-Alt-f / Format via sql-formatter; light/dark themes from design tokens. Replace the layout useEffect with a callback ref. Dedupe @codemirror/* via package.json overrides to fix duplicate @codemirror/state instances. Drop the Monaco SQL language registration and the monaco-editor sql module shim; Monaco stays for the YAML/TS surfaces.
1 parent 645fed8 commit b9b144c

11 files changed

Lines changed: 493 additions & 376 deletions

File tree

frontend/bun.lock

Lines changed: 44 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,18 @@
6363
"@chakra-ui/portal": "^2.1",
6464
"@chakra-ui/react-use-disclosure": "^2.1",
6565
"@chakra-ui/system": "^2.1",
66+
"@codemirror/autocomplete": "^6.20.3",
67+
"@codemirror/lang-sql": "^6.10.0",
68+
"@codemirror/language": "^6.12.3",
69+
"@codemirror/state": "^6.6.0",
70+
"@codemirror/view": "^6.43.1",
6671
"@connectrpc/connect": "^2.1.0",
6772
"@connectrpc/connect-query": "^2.2.0",
6873
"@connectrpc/connect-web": "^2.1.0",
6974
"@emotion/css": "^11.13.5",
7075
"@hookform/resolvers": "^5.2.2",
7176
"@icons-pack/react-simple-icons": "^13.8.0",
77+
"@lezer/highlight": "^1.2.3",
7278
"@milkdown/kit": "^7.18.0",
7379
"@milkdown/react": "^7.18.0",
7480
"@modelcontextprotocol/sdk": "^1.29.0",
@@ -86,6 +92,7 @@
8692
"@tanstack/react-virtual": "^3.13.12",
8793
"@tanstack/zod-adapter": "^1.167.0",
8894
"@types/prismjs": "^1.26.5",
95+
"@uiw/react-codemirror": "^4.25.10",
8996
"@xyflow/react": "^12.9.2",
9097
"ai": "^6.0.168",
9198
"array-move": "^4.0.0",
@@ -200,6 +207,13 @@
200207
"vitest-browser-react": "^2.2.0"
201208
},
202209
"overrides": {
210+
"@codemirror/autocomplete": "^6.20.3",
211+
"@codemirror/commands": "^6.10.3",
212+
"@codemirror/language": "^6.12.3",
213+
"@codemirror/lint": "^6.9.7",
214+
"@codemirror/search": "^6.7.0",
215+
"@codemirror/state": "^6.6.0",
216+
"@codemirror/view": "^6.43.1",
203217
"dompurify": "^3.4.0",
204218
"prismjs": "^1.30.0",
205219
"baseline-browser-mapping": "2.10.33"

frontend/rsbuild.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export default defineConfig({
186186
semicolons: true,
187187
}),
188188
new MonacoWebpackPlugin({
189-
languages: ['yaml', 'json', 'typescript', 'javascript', 'protobuf', 'sql'],
189+
languages: ['yaml', 'json', 'typescript', 'javascript', 'protobuf'],
190190
customLanguages: [
191191
{
192192
label: 'yaml',

frontend/src/components/pages/sql/sql-editor.test.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ import { beforeEach, describe, expect, test, vi } from 'vitest';
1515
import { SqlEditor } from './sql-editor';
1616
import type { SqlRole } from './sql-types';
1717

18-
// Monaco doesn't run in jsdom; the editor surface is exercised manually/e2e.
19-
vi.mock('components/misc/kowl-editor', () => ({
18+
// CodeMirror's layout/measure loop doesn't run in jsdom; the editor surface is
19+
// exercised manually/e2e.
20+
vi.mock('@uiw/react-codemirror', () => ({
2021
default: ({ value }: { value: string }) => <div data-testid="editor">{value}</div>,
2122
}));
2223

@@ -27,7 +28,7 @@ const QUERY_2_TAB = /Query 2/;
2728
const RUN_BUTTON = /Run (Ctrl|)/;
2829

2930
const renderEditor = (onRun = vi.fn()) => {
30-
render(<SqlEditor identifiers={[]} initialQuery="SELECT 1;" onRun={onRun} role={ADMIN} />);
31+
render(<SqlEditor catalogs={[]} initialQuery="SELECT 1;" onRun={onRun} role={ADMIN} />);
3132
return onRun;
3233
};
3334

0 commit comments

Comments
 (0)