Repository navigation
feat(highlight): dialect-aware SQL syntax highlighting (API, CLI, LSP, WASM, playground) - #825
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Claude finished @ajitpratap0's task in 26s —— View job Review of PR #825: dialect-aware syntax highlightingI read the core of Overall this is well-structured and carefully defended. The renderers escape output, sanitize prefixes, and Potential issues
Security
Performance
TestsThe coverage described is strong: corpus test, fuzzing, UTF-16 conversion tests and dialect tests. Suggestions:
Notes
No blocking issues found. |
|
Claude finished @ajitpratap0's task in 35s —— View job Review of PR #825: dialect-aware syntax highlightingI read No blocking issues. The earlier review's items still stand; this pass checked them against the code. Findings
Other notes
|
ccd299e to
d9c287f
Compare
|
Claude finished @ajitpratap0's task in 22s —— View job Review of PR #825: dialect-aware syntax highlightingI re-checked the points raised in the earlier reviews against Worth fixing
Minor
Looks good
|
Add pkg/highlight, a syntax highlighter built on the tokenizer, and expose it through the gosqlx API, CLI, LSP, WASM and the playground. - highlight.Spans classifies SQL into sorted byte-offset spans with 13 stable categories; functions/types are detected by context, prefixed literals stay whole, and invalid SQL is highlighted up to the first lexical error (rest marked error). Tab-aware offset mapping and validated error positions work around tokenizer location quirks. - Renderers: ANSI (256/true color/attributes), HTML (classes or inline styles, escaped), CSS; dark/light/mono themes; JSON-serializable spans. - gosqlx.Highlight/HighlightANSI/HighlightHTML convenience functions. - `gosqlx highlight` (alias hl): ansi|html|json|css, --theme, --dialect, --color auto|always|never (TTY, NO_COLOR, COLORTERM), --standalone. - LSP semantic tokens use the standard legend, UTF-16 positions, per-line splitting and the dialect from initializationOptions; the VS Code extension restarts the server when gosqlx.dialect changes. - WASM gosqlxHighlight returns UTF-16 spans; the playground decorates CodeMirror with them, falling back to Lezer until WASM is ready. - Docs: HIGHLIGHTING.md, CLI/API/LSP/usage guides, README, CHANGELOG. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KTj1PEbxzVCETkeYrZKcrE
The playground loads CodeMirror plus the GoSQLX highlighting bridge and was already at ~419 KB of the 420 KB script budget derived from the homepage; highlighting adds ~780 B gzipped. Split assertions into an assertMatrix: /playground/ gets 480 KB (measured 420 KB + ~15%), every other route keeps 420 KB. README updated with the measurement. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KTj1PEbxzVCETkeYrZKcrE
#826 made tokenizer columns count one byte per tab and fixed token Start after trivia. Drop the tab-as-4 offset adjustment, reject locations past their line, adapt the new LSP tab/comment offset test to the highlight-based encoder (comments are now emitted as tokens), and skip the fuzz ANSI round-trip check for inputs that already contain escape sequences (source text is passed through verbatim). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KTj1PEbxzVCETkeYrZKcrE
d9c287f to
7da75d9
Compare
|
Claude finished @ajitpratap0's task in 20s —— View job Review of PR #825: dialect-aware syntax highlightingI re-checked the earlier review points against Worth fixing
Minor
Looks good
|
|
Claude finished @ajitpratap0's task in 20s —— View job Review of PR #825: dialect-aware syntax highlightingI re-checked the points from the earlier reviews against Worth fixing
Minor
Looks good
|
Resolve conflicts with #825 (syntax highlighting) and #829 (dialect lists): CHANGELOG [Unreleased] Added keeps both entries; pkg/mcp/server.go unions the imports and derives supportedDialects from keywords.DialectNames, used for the validate_sql description and enum. Also correct the validate-sql.sh fallback comment: the greedy sed match takes the last file_path value, not the first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RkzVu3JY9Y6BRWfjesWts9
Summary
Adds SQL syntax highlighting as a first-class GoSQLX capability.
Core — new
pkg/highlighthighlight.Spans(sql, opts...)classifies SQL into sorted, non-overlapping byte-offset spans with 13 stable categories: keyword, function, type, identifier, quoted-identifier, string, number, constant, operator, punctuation, comment, placeholder, error.WithDialect.x::int,CAST(x AS DATE),Nullable(String);N'..',E'..',0x1F,:name,@@var.errorspan. Works for incomplete editor input.Surfaces
gosqlx.Highlight,gosqlx.HighlightANSI,gosqlx.HighlightHTML.gosqlx highlight(aliashl) with-f ansi|html|json|css,--theme,--dialect,--color auto|always|never(honors TTY,NO_COLORandCOLORTERM) and--standalone.semanticTokens/fullnow usespkg/highlight.initializationOptions.dialect.gosqlx.dialectchanges.gosqlxHighlight(sql[, dialect])returns spans with UTF-16 offsets.docs/HIGHLIGHTING.md, plus updates to the CLI/API/LSP/usage guides, README, llms.txt, CLAUDE.md and the CHANGELOG[Unreleased]section.Test Plan
task check: fmt, vet, golangci-lint (0 issues), race tests; plustask test:cbinding.pkg/highlighttests:FuzzSpansfor about 2.6M executions with strict invariants:NO_COLOR, bad flags, stdin and file input.GOOS=js GOARCH=wasmbuild.gosqlxHighlightin the console.BenchmarkSpanstakes about 45µs for 2 KB, roughly twice the cost of tokenizing alone. The tokenizer and parser hot paths are untouched.Breaking Changes
None to the Go API. The LSP semantic token legend changed:
identifieris replaced by the standardvariabletype.variable; they werestring.Clients read the legend at initialize, so nothing breaks at the protocol level. Users with custom styling keyed on the old
identifiertype (for example Neovim@lsp.type.identifier) need to update it. This is recorded under Behavior changes in the CHANGELOG.Follow-ups, not in this PR:
gosqlx.dialectenum list fewer dialects than the code accepts.Type of Change
Performance Impact
Test Coverage
pkg/highlight: about 91% (new package)Checklist
🤖 Generated with Claude Code
https://claude.ai/code/session_01KTj1PEbxzVCETkeYrZKcrE