Repository navigation
Web UI: rainbow parentheses, matched brackets, matching identifiers, digit groups - #109108
Conversation
…digit groups
Extend the syntax highlighting in the Web UI (`play.html`) backdrop to match
the features of `clickhouse-client`:
- Rainbow parentheses: brackets (`()`, `[]`, `{}`) are colored by nesting depth,
cycling through seven colors. The palettes are dark for the light theme and
light for the dark theme.
- Matched brackets: the bracket pair around the cursor is emphasized in bold.
- Matching identifiers: when the cursor is inside an identifier, every occurrence
of the same identifier is underlined together.
- Digit groups: long plain decimal numbers get a subtle underline at each
thousands boundary, mirroring the `highlightWithLexer` algorithm in
`src/Client/ClientBaseHelpers.cpp`.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Workflow [PR], commit [d99b93a] Summary: ✅
AI ReviewSummaryThis PR adds four new lexer-driven highlighting behaviors to Findings
Final Verdict
|
…tion-name detection Address the AI review on PR #109108 (#109108) with two fixes to `play.html` syntax highlighting, both aligning the Web UI with `highlightWithLexer` in `src/Client/ClientBaseHelpers.cpp`: - `computeBracketInfo` assigned a rainbow depth to every opening bracket eagerly and gave unmatched closing brackets depth `0`, so a lone `(`, a stray `)`, or a mismatched pair rendered as a normal `q-br*` bracket. Now a bracket receives a depth (and thus a rainbow color) only once it has a real mate; unmatched brackets stay at depth `-1` and keep the default color, as `clickhouse-client` does. - `tokenClass` skipped only `Whitespace` when deciding whether a `BareWord` is a function name, so `sum/*c*/(x)` was classified as a plain identifier and underlined by the matching-identifier pass. It now skips `Comment` too, so such function names are excluded, matching the CLI. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Addressed both Majors from the AI review in 7b71cef (
There is no JS unit-test harness for |
|
I looked into the remaining AI Major ( Semicolon reset. The AI claims matching Crossing nest
Both are defensible — it's a UX call. Test. The regression coverage the AI asks for is feasible via the existing I've left the code untouched since this is your design call, not a correctness/safety issue. Happy to implement whichever variant you pick plus the gtest. |
…boundaries `computeBracketInfo` in `play.html` assigned a rainbow depth to a bracket only after finding a properly-nested mate, but it left the outstanding openers on the stack after a mismatched closer and across `;` boundaries. A later closer could then reach over the break and retroactively "match" an opener that was never properly closed: `SELECT ([)]` still rainbow-colored `[` / `]`, and `SELECT (; SELECT )` matched the `)` in the second statement back to the `(` in the first. Discard the outstanding openers when a closer does not match the innermost opener, and reset the stack at each `;`, so a bracket from a broken or a previous statement can no longer become matchable. A valid pair after the break or after the `;` is still colored.
There is no JavaScript/WebAssembly runtime in CI, so we cannot run the browser code directly. Port the depth-assignment part of `computeBracketInfo` on top of the real `DB::Lexer` — exactly as `gtest_play_get_query_under_cursor.cpp` already does for `getQueryUnderCursor` — and lock the contract that a bracket is colored only once it has a real, properly-nested mate: - proper nesting across all bracket kinds gets ascending depths; - a lone `(`, a stray `)`, or a simple mismatch stays uncolored; - a crossing nest such as `([)]` colors nothing (the `]` must not reach over the stray `)` to match the `[`); - brackets do not match across a `;` statement boundary, while a fresh pair after the break or the `;` is still colored.
The bracket matcher in `play.html` reset its stack at every `;`, so `SELECT (; SELECT )` left the `(` / `)` unmatched. But `clickhouse-client`'s rainbow loop (`highlightWithLexer` in `src/Client/ClientBaseHelpers.cpp`) skips `;` without clearing `brace_stack`, so it still matches the `(` with a `)` in a later statement. The reset therefore diverged from the client this change claims parity with (AI review finding on commit `4f4ccadc`). Drop the `TT.Semicolon` reset in `computeBracketInfo` to restore parity. The crossing-nest fix (a mismatched closer discards the outstanding openers, so `([)]` colors nothing) is a separate, genuine `play.html`-only correction and is left in place. Update the regression gtest accordingly: `(; )` and `SELECT (; SELECT )` now match with depth 0, mirroring the client. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
| /// Prefer the bracket ending at the cursor (the char just before the caret), then | ||
| /// fall back to the bracket starting at the cursor (the char just after). | ||
| let found = -1; | ||
| for (let i = 0; i < tokens.length; ++i) { | ||
| const type = tokens[i].type; | ||
| if (!OPENING_BRACKETS.has(type) && !CLOSING_BRACKETS.has(type)) continue; | ||
| if (starts[i] + tokens[i].token.length === cursor) { found = i; break; } | ||
| } | ||
| if (found < 0) { | ||
| for (let i = 0; i < tokens.length; ++i) { | ||
| const type = tokens[i].type; | ||
| if (!OPENING_BRACKETS.has(type) && !CLOSING_BRACKETS.has(type)) continue; | ||
| if (starts[i] === cursor) { found = i; break; } | ||
| } | ||
| } | ||
| if (found >= 0 && matchOf[found] >= 0) { | ||
| bold.add(found); |
There was a problem hiding this comment.
computeBracketInfo only sets found when the caret is exactly at a bracket boundary. A query like (ab) with the caret between a and b leaves found == -1, so the new q-br-match style never appears even though the cursor is still inside a matched pair.
That falls short of the PR's “bracket pair around the cursor” behavior. Can we select the innermost matched pair whose open/close offsets surround cursor (and add a regression case for a non-adjacent cursor position) instead of only the bracket immediately before/after the caret?
|
Looked into the remaining AI Major ( What the client does. The interactive client brightens a matched pair only when the caret is on a bracket, never for a caret in the middle of the enclosed text. In So the current adjacent-only behavior is the parity behavior; making it fire for a caret anywhere inside the pair is the divergence (same shape as the earlier
Left the code untouched since this is a parity/UX call, not a correctness issue. Happy to implement the enclosing-pair variant plus a non-adjacent-caret gtest case if you want the divergence. |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 60/61 (98.36%) · Uncovered code |
|
I made it more washed deliberately after the first iteration, because otherwise their contrast is similar to other syntax elements, and it becomes too much. PS. Maybe not contrast, but perceived brightness. |
…ntax-error-position Resolve conflicts in `programs/server/play.html` between this PR's syntax-error position highlight and the Web UI features that merged into `master` in the meantime (query tabs `#107826`, expanded-database restore `#108964`, and rainbow-bracket / matched-identifier highlighting `#109108`). - `postSingle` now takes both `params_restore_pending` (tabs feature) and `queryStart` (this PR); all call sites use the newer `my_request_num` ownership handling and pass both arguments. - The token render loop keeps `master`'s rainbow-bracket, bold matched-bracket, matched-identifier and per-digit-group number rendering, and additionally OR-s the `q-err-pos` class onto the token at the reported error position. The net diff of the branch over `master` is exactly this PR's syntax-error-highlight feature; no tabs / restore / bracket functionality was dropped.
…tion-name detection Address the AI review on PR ClickHouse#109108 (ClickHouse#109108) with two fixes to `play.html` syntax highlighting, both aligning the Web UI with `highlightWithLexer` in `src/Client/ClientBaseHelpers.cpp`: - `computeBracketInfo` assigned a rainbow depth to every opening bracket eagerly and gave unmatched closing brackets depth `0`, so a lone `(`, a stray `)`, or a mismatched pair rendered as a normal `q-br*` bracket. Now a bracket receives a depth (and thus a rainbow color) only once it has a real mate; unmatched brackets stay at depth `-1` and keep the default color, as `clickhouse-client` does. - `tokenClass` skipped only `Whitespace` when deciding whether a `BareWord` is a function name, so `sum/*c*/(x)` was classified as a plain identifier and underlined by the matching-identifier pass. It now skips `Comment` too, so such function names are excluded, matching the CLI. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…lighting-brackets-identifiers Web UI: rainbow parentheses, matched brackets, matching identifiers, digit groups
…ntax-error-position Resolve conflicts in `programs/server/play.html` between this PR's syntax-error position highlight and the Web UI features that merged into `master` in the meantime (query tabs `ClickHouse#107826`, expanded-database restore `ClickHouse#108964`, and rainbow-bracket / matched-identifier highlighting `ClickHouse#109108`). - `postSingle` now takes both `params_restore_pending` (tabs feature) and `queryStart` (this PR); all call sites use the newer `my_request_num` ownership handling and pass both arguments. - The token render loop keeps `master`'s rainbow-bracket, bold matched-bracket, matched-identifier and per-digit-group number rendering, and additionally OR-s the `q-err-pos` class onto the token at the reported error position. The net diff of the branch over `master` is exactly this PR's syntax-error-highlight feature; no tabs / restore / bracket functionality was dropped.






Extend the syntax highlighting in the Web UI (
play.html) backdrop to reach parity withclickhouse-client:(),[],{}) are colored by their nesting depth, cycling through seven colors. A type-aware stack assigns each opening bracket its depth and gives the matching closing bracket the same color. The palettes are dark for the light theme and light for the dark theme.highlightWithLexeralgorithm insrc/Client/ClientBaseHelpers.cpp: only the integer part of a regular base-10 number (at least 5 digits, no exponent / hex / bin /_separators) is considered.All highlighting is computed from the existing WASM lexer token stream and re-rendered on cursor movement.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added rainbow parentheses, matched-bracket, matching-identifier, and digit-group highlighting to the Web UI (
play.html), matchingclickhouse-client.Documentation entry for user-facing changes
🤖 Generated with Claude Code
Version info
26.7.1.464(included in26.7and later)