Skip to content

feat: render grammar value coloring + color settings (#467 #342)#480

Open
SJrX wants to merge 1 commit into
issue-345-10from
issue-345-11
Open

feat: render grammar value coloring + color settings (#467 #342)#480
SJrX wants to merge 1 commit into
issue-345-10from
issue-345-11

Conversation

@SJrX

@SJrX SJrX commented Jun 21, 2026

Copy link
Copy Markdown
Owner

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.

Stacked on #479 (issue-345-10).

Pieces

  • UnitFileHighlighter — four user-customizable TextAttributesKeys, one per Role: GRAMMAR_ENUM/LITERAL/OPERATOR/IDENTIFIER, defaulting to CONSTANT/NUMBER/OPERATION_SIGN/IDENTIFIER.
  • GrammarValueColorAnnotator — flag-gated. For grammar-backed options it runs colorize(value) and paints each Region with 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.
  • CombinatorsIPV4_ADDR / IPV6_ADDR wrapped in Labeled(LITERAL) so an address colours as one literal span, not per-octet/hextet. Labeled is transparent to matching, and the full suite confirms validation/completion are unchanged. colorize() now dedupes identical regions (handles nested Labeled, 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 with DefaultLanguageHighlighterColors fallbacks.

Tests

GrammarValueColorAnnotatorTest: SocketBindAllow=ipv4:tcp:8080 colours ipv4→enum, :→operator, 8080→literal; Gateway=192.168.1.1 colours the whole address as one span; nothing when the flag is off. Plus the extended ColoringTest.

Try it

./gradlew runIde, enable the flag, open a .service/.network file — SocketBindAllow=, RestrictAddressFamilies=, IP-bearing options, and RootImagePolicy= now colour by role. Tune colors under Settings → Editor → Color Scheme → Unit Files (systemd) → Value.

Refs #467 #342

🤖 Generated with Claude Code

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>
@github-actions

Copy link
Copy Markdown

Test Results

1 142 tests  +4   1 142 ✅ +4   48s ⏱️ -2s
  303 suites +1       0 💤 ±0 
  303 files   +1       0 ❌ ±0 

Results for commit 23baad8. ± Comparison against base commit 5fb3d64.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant