feat: render grammar value coloring + color settings (#467 #342)#480
Open
SJrX wants to merge 1 commit into
Open
feat: render grammar value coloring + color settings (#467 #342)#480SJrX wants to merge 1 commit into
SJrX wants to merge 1 commit into
Conversation
The rendering half of grammar coloring — now visible in the editor behind the flag. - UnitFileHighlighter: four user-customizable TextAttributesKeys, one per Role (GRAMMAR_ENUM/LITERAL/OPERATOR/IDENTIFIER), defaulting to CONSTANT/NUMBER/ OPERATION_SIGN/IDENTIFIER colors. - GrammarValueColorAnnotator: flag-gated; for grammar-backed options it runs colorize() and paints each Region with the matching attributes key. No-op when the flag is off. - UnitFileColorSettings: adds the four roles under "Value" (customizable + themed) and extends the preview with grammar examples — RestrictAddressFamilies, SocketBindAllow/ Deny, IPAddressAllow, RootImagePolicy — via highlighting tags. - Combinators: IPV4_ADDR / IPV6_ADDR wrapped in Labeled(LITERAL) so an address colours as one literal span rather than per-octet/hextet (transparent to matching; full suite green confirms validation/completion unchanged). colorize() now dedupes identical regions (nested Labeled, e.g. IPv4 suffix inside IPv6). Tests: GrammarValueColorAnnotatorTest (SocketBindAllow coloured by role; an IP as one literal span; nothing when the flag is off) and the extended ColoringTest. Refs #467 #342 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
What
The rendering half of grammar coloring — this is the part that's actually visible in the editor (behind the experimental flag). #479 computed
Regions; this paints them.Pieces
UnitFileHighlighter— four user-customizableTextAttributesKeys, one perRole:GRAMMAR_ENUM/LITERAL/OPERATOR/IDENTIFIER, defaulting toCONSTANT/NUMBER/OPERATION_SIGN/IDENTIFIER.GrammarValueColorAnnotator— flag-gated. For grammar-backed options it runscolorize(value)and paints eachRegionwith the matching key. No-op when the flag is off.UnitFileColorSettings— the four roles now appear under Value in Settings → Editor → Color Scheme → Unit Files (systemd) (customizable + theme-aware), and the preview shows real grammar examples:RestrictAddressFamilies,SocketBindAllow/SocketBindDeny,IPAddressAllow,RootImagePolicy.Combinators—IPV4_ADDR/IPV6_ADDRwrapped inLabeled(LITERAL)so an address colours as one literal span, not per-octet/hextet.Labeledis transparent to matching, and the full suite confirms validation/completion are unchanged.colorize()now dedupes identical regions (handles nestedLabeled, e.g. an IPv4 suffix inside an IPv6 address).Color mapping (tunable)
ENUM→CONSTANT,LITERAL→NUMBER,OPERATOR→OPERATION_SIGN,IDENTIFIER→IDENTIFIER — all overridable in the settings page. Easy to retune since they're our own keys withDefaultLanguageHighlighterColorsfallbacks.Tests
GrammarValueColorAnnotatorTest:SocketBindAllow=ipv4:tcp:8080coloursipv4→enum,:→operator,8080→literal;Gateway=192.168.1.1colours the whole address as one span; nothing when the flag is off. Plus the extendedColoringTest.Try it
./gradlew runIde, enable the flag, open a.service/.networkfile —SocketBindAllow=,RestrictAddressFamilies=, IP-bearing options, andRootImagePolicy=now colour by role. Tune colors under Settings → Editor → Color Scheme → Unit Files (systemd) → Value.Refs #467 #342
🤖 Generated with Claude Code