feat: Web console: replace Ace with CodeMirror 6 #20507
All Vouch review confidence checks passed
Residual risk 0.23 = Change Risk (0.57) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.57 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #20507"
general
weight: 0.35
clintropolis
Note from the human
When the console was started I used Ace because it was the only editor that could support all the features the console needed. Ace is really a pain to use, the documentation is basically non existent. Everything the console does with Ace is basically a hack. I have always dreamed of switching to one of the more popular editors but it always felt like a mountain of effort. Well Claude Opus 5.5 did it, and tidied up all the code to remove all the Ace-isms that were all over the place, and it fixed some bugs in highlighting and completions. Otherwise everything is pixel perfect (except for a few nothingburger edge cases). You can see a migration plan file that I checked in then deleted if you want to follow the reasoning. I reviewed the results after each commit.
We are living in the future.
This branch also migrates the console build to mise as volta is deprecated and bumps
http-cache-semanticsto avoid a reported npm issue---
AI Summary
The web console's code editors moved from Ace (
ace-builds+react-ace) to CodeMirror 6. All the editors now share oneCodeEditorcomponent: the workbench, the explore view's SQL inputs, JSON inputs, spec and value dialogs, history and explain. Two Lezer grammars, one for DruidSQL and one for Hjson, drive the highlighting and the completions.The goal was to keep the console looking and behaving the same. On top of that, the code was cleaned up until it reads as if the console had used CodeMirror from the start, with no Ace-shaped leftovers. Where the behavior changes, it's either a bug fix or listed below.
What changed
Editor (
src/components/code-editor/)CodeEditor: a controlled component (value/onChange). The props that change at runtime are applied through CodeMirror compartments: language, read-only, line numbers, padding, transparent background and placeholder.refgives the CodeMirrorEditorView.stateCacheId/forgetEditorState: they keep the undo history and selection between mounts, usingEditorState.toJSON. They replaceAceEditorStateCache.code-editor-theme.ts): reproduces the previous look (solarized_dark colors with the console's overrides).<body>, so dialogs and popovers don't clip them.search-panel.tsx) instead of CodeMirror's default panel.showEditorError(error-mark.ts) underlines a parse error in the text and shows the message as adata-tooltipon hover.JsonInputand the workbench (for JSON queries) use it.CLEANUP.md, which records what was cleaned up and which Ace behaviors were kept on purpose.Languages (
src/editor-languages/)dsql.grammar: DruidSQL tokens and nested parentheses.- An external specializer decides which identifiers are keywords, functions, constants or types.
-
getDsqlLanguage(availableSqlFunctions)makes a language that also knows the functions the cluster reports.- This replaces the global
initAceDsqlMode.hjson.grammar: a real Hjson grammar: objects, properties, arrays, the root object without braces, strings with escapes, and comments. An external tokenizer handles quoteless keys and quoteless strings.dsql(options)/hjson({ jsonCompletions }): each returns aLanguageSupportthat brings its own completions and bracket closing.script/build-grammars.mjsbuilds them at build time. They are gitignored, likelib/sql-docs.ts, and run as part ofscript/buildandnpm run test-unit.lib/keywords.tsmoved tosrc/editor-languages/dsql-keywords.ts.Completions (
src/editor-completions/)Completions with a structureddoc(name, syntax, description), notdocHTML. The SQL docs are now "doc markdown" rendered as DOM, with no HTML strings;snarkdownwas removed.- comments and literals are detected from the tree;
- the keyword before the cursor is found through the tree, including one on an earlier line or past a comment;
- the SQL references and literals are collected from tree nodes;
- the Hjson context (
hjson-context.ts, which replaces the 400-line scanner inutils/) now sees the properties after the cursor too.$as a word character. Hjson treats$and-as word characters.Positions
RowColumnis replaced by the 1-basedLineColumneverywhere, which matches how Druid, Hjson and CodeMirror number lines.-
offsetToRowColumn→offsetToLineColumn-
DruidError.startRowColumn→DruidError.startLineColumn, and the same forend-
getRowColumnFromIssue→getLineColumnFromIssue-
QuerySlice.startRowColumn→QuerySlice.startLineColumn, and the same forend-
extractRowColumnFromHjsonError→extractLineColumnFromHjsonErrorfocusEditorAt(view, position)replaces thegoToPositionimperative handles.Workbench
sub-query-markers.ts).- A state field finds the queries in the text.
- Each marker is a real DOM run button with a "Run this query" tooltip, replacing the CSS pseudo-element drawing.
- Hovering a button highlights its query.
User-visible changes
- Values containing colons (timestamps,
host:port, URLs) are no longer partly shown as keys. That affected 97 of the 452 valid JSON examples in the Druid docs.- Quoteless values are highlighted as whole strings.
- A word that is being typed inside an object is shown as a key.
- An unclosed quoted string ends at the end of its line.
- An unclosed
'…or"…is colored as a string or identifier up to the end of the line.- A sign is an operator:
a-1isa,-,1.- A function with several signatures is listed once, with every signature in the doc panel.
- Docs like
ARRAY<STRING>are no longer swallowed as HTML.- The word being typed is not suggested back.
-
{is not auto-closed in SQL.- In SQL,
-no longer joins words, soSELECT a-cocompletesco.- Hjson completion rules can depend on properties written below the cursor.
Dependencies and licenses
@codemirror/{autocomplete,commands,language,search,state,view}and@lezer/{common,highlight,lr}.@lezer/generatoris a dev dependency, used only at build time.ace-builds,react-aceandsnarkdown.licenses.yamlandlicenses/binwere updated. The CodeMirror packages and their dependencies (style-mod,w3c-keyname,crelt,@marijn/find-cluster-break) are all MIT. Theace-builds,react-aceandfast-equalsentries were removed.Testing
npm run test-unitpasses, with 850 Jest tests.- the grammars (node names, unterminated tokens, Hjson edge cases, highlight styles);
- the Hjson context;
- SQL and Hjson completions, the completion source and its word characters;
- doc rendering, the error mark, the sub-query markers;
-
CodeEditoritself (find/replace, state caching).- workbench highlighting, completions and docs;
- run-query markers;
- undo history surviving tab switches;
- find/replace;
- JSON error underline and tooltip;
- explore-view SQL inputs.
---
Prompt for migrating a fork or feature branch that still uses Ace