Repository navigation
fix(editor): colour the SQL keywords, literals and functions the grammar already names (#2634) - #2635
Merged
Merged
Conversation
# Conflicts: # CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2634.
INandANDwere one of six SQL token classes the editor silently refused to colour, and the same cause left the MongoDB and Elasticsearch editors with no highlighting at all.Root cause
CaptureName.fromStringis a closed 21-string whitelist that predates the dotted capture names every bundled tree-sitter grammar emits.TreeSitterClient+Highlight.swift:105andTreeSitterClient+Temporary.swift:44both drop a capture the whitelist cannot name, so the token keeps the plain text attributes and simply looks unhighlighted. The grammars' capture names and the editor's vocabulary are two hand-maintained lists that must agree, and nothing forced them to.Two more defects of the same class sat underneath it:
(literal) @stringsits at capture index 4 and wins the lower-index-wins dedupe against@number(7),@float(8) and@type.builtin(16), so every numeric literal and everyNULL,TRUEandFALSErendered in the String colour. The#match?predicates meant to separate them are nvim Lua patterns (^[-+]?%d+$); SwiftTreeSitter compiles#match?intoNSRegularExpression, where%dis a literal%followed bydand never matches.CodeLanguage.javascriptdeclareshighlights: ["injections"], soTreeSitterModel.queryForconcatenatesinjections.scm+highlights.scmandtry?s the result.injections.scmreferenced(glimmer_template), a node the vendored parser does not have, andhighlights.scmused(function, which this parser callsfunction_expression.TreeSitterModel.shared.query(for: .javascript)returned nil, so the MQL and Query DSL editors had no highlighting whatsoever.locals.scmandtags.scmfailed on the same renamed node; nothing loads them today, so they were inert, but they shipped broken.ThemeEngine.makeEditorTheme()also never readsyntax.operatororsyntax.function, andEditorThemehad no attribute that could carry them, so the Operator and Function pickers in Settings > Appearance changed the preview card and nothing else.Measured
A harness linking the vendored
CodeEditLanguagesand replicatinghighlightsFromCursorexactly, overSELECT CAST(total AS INT), 42, NULL, 'abc' FROM orders o WHERE o.status IN ('a') AND o.total = 3 GROUP BY o.status ORDER BY total DESC;INANDBYDESCINTCASTorders423NULL'abc'=(),;JSON gains
true/false/nullin the NULL colour, matching whatJSONRowColorsalready paints in the inspector's tree mode. Bash gains|,>and command flags. JavaScript gains all highlighting, from none.The fix
.scma bundled grammar ships, not only the ones aCodeLanguageloads, so a query file cannot ship broken again.CaptureNamegainsoperatorandconstant, plus agrammarAliastable mapping the nvim-treesitter names the bundled grammars emit onto this editor's vocabulary. Names deliberately left uncoloured are listed inunstyledGrammarCapturesnext to it rather than being invisible.EditorThemegainsoperatorsandfunctions;.function/.methodmove offvariables, which TablePro fills with the NULL colour.ThemeEngine.makeEditorTheme()passessyntax.operatorandsyntax.function, so both pickers now do what their labels say.tree-sitter-sql/highlights.scm: ICU regex for the two predicates, and@number,@floatand a new@constant.builtinblock hoisted above(literal) @string;@function.callhoisted above@type.tree-sitter-javascript: eleven(functionrenamed to(function_expressionacrosshighlights,localsandtags, and the Emberglimmer_templatepattern removed frominjections.Deliberately not doing
@fieldstays uncoloured, so column identifiers keep the plain text colour: of TablePlus, DataGrip, Postico, Sequel Ace and VS Code, only DataGrip colours them.@punctuation.*stays uncoloured for the same reason and because it costs a dense viewport 440 extra highlight ranges (1560 against 1120).@spelland@embeddedmark a range for another tool and sit on a range something else already colours.Chose an alias table over a fallback rule
The first draft resolved a dotted name by stripping trailing components, which is neovim's documented rule and what these
.scmfiles were written against. The Phase 2 critique showed why it is worse here: with the new guard test, an unknown capture fails CI loudly, whereas a stripping loop would silently resolve it to something plausible and possibly wrong.type.qualifieris the example: stripping givestype, butUNIQUEandCASCADEread as keywords.Verified
buildPASStest(13 suites: the new one plus every suite owningEditorTheme,ThemeEngineor the editor fixture) PASS, 127 cases, 0 failureslint0 violations across the seven changed Swift filesmainat v0.72.0No docs change: Settings > Appearance already documents Operator and Function as syntax colours, and this makes that true. The
sql-editorpage's images are still the "Screenshot coming soon" placeholders, so nothing there goes stale.Before / after
The change is entirely colour inside the editor, so the table above is the exact per-token record, taken from the shipping query files through the shipping resolution path. A rendered light and dark pair of the same sample went to the author to drag in here;
ghcannot upload an image to a pull request.Reading the sample in Default Light, before against after:
IN,AND,ON,NOT,BY,DESCandUNIQUEgo from black to the keyword blue;INT,VARCHAR,JSONBandTIMESTAMPfrom black to the type teal;CASTandcountfrom black to the function teal;42,3.5,100and255from the string red to the number purple;NULLandTRUEfrom the string red to the NULL orange. Quoted literals, table names and aliases are unchanged.https://claude.ai/code/session_016cKgYoccE88XFeVPuBLRak