Skip to content

fix: leave free-form string values at the default color (#467 #342)#483

Closed
SJrX wants to merge 1 commit into
issue-345-13from
issue-345-14
Closed

fix: leave free-form string values at the default color (#467 #342)#483
SJrX wants to merge 1 commit into
issue-345-13from
issue-345-14

Conversation

@SJrX

@SJrX SJrX commented Jun 21, 2026

Copy link
Copy Markdown
Owner

What

The default coloring heuristic mapped RegexTerminal → IDENTIFIER, so free-form values — Description=, interface names like Bond=bond1, etc. — got recolored as identifiers. That felt wrong: those should keep the editor's normal value color. Make RegexTerminal uncolored by default.

Stacked on #482 (issue-345-13). Effectively walks back the auto-identifier coloring (and the Identifier preview example added in #482).

Changes

  • defaultRole: RegexTerminal now falls through to null (no grammar coloring) — free-form names/strings keep the default value color.
  • Color settings: drop the Identifier (grammar) descriptor, its demo tag, and the Description= example, since nothing uses the IDENTIFIER role by default anymore.
  • Kept: the Role.IDENTIFIER enum and its GRAMMAR_IDENTIFIER key, so a grammar can still opt a specific field in via Labeled(Role.IDENTIFIER, …) later (e.g. a single-token, can't-be-space-separated field like User=) — at which point we'd re-add the descriptor + example.

Enum / Literal / Operator coloring is unchanged. Full suite green.

Refs #467 #342

🤖 Generated with Claude Code

The default heuristic mapped RegexTerminal -> IDENTIFIER, so free-form values like
Description= and interface names (Bond=) got recoloured, which felt wrong — those
should keep the editor's normal value color. Make RegexTerminal uncoloured by default.

- defaultRole: RegexTerminal now falls through to null (no coloring).
- Drop the Identifier descriptor + tag + demo example from the color settings page,
  since nothing uses the IDENTIFIER role by default now. The Role and its key are kept
  for grammars that opt in explicitly via Labeled later (e.g. a single-token User=).

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  ±0   1 142 ✅ ±0   45s ⏱️ -3s
  303 suites ±0       0 💤 ±0 
  303 files   ±0       0 ❌ ±0 

Results for commit 99723b8. ± Comparison against base commit 788fd59.

SJrX pushed a commit that referenced this pull request Jun 29, 2026
IDENTIFIER was defined (enum value, GRAMMAR_IDENTIFIER attributes key, annotator
branch) but never produced: defaultRole never returns it, nothing wraps a value
in Labeled(Role.IDENTIFIER), and it has no color-settings descriptor. It was the
role intended for free-form names — but #483 settled that free-form values keep
the editor's default color, which leaves IDENTIFIER with no purpose. Remove it;
the taxonomy is ENUM / LITERAL / OPERATOR (plus uncoloured default).
SJrX added a commit that referenced this pull request Jun 29, 2026
* feat: grammar coloring engine layer — roles, defaults, optional Labeled (#467 #342)

Adds the (pure, IntelliJ-free) substrate for grammar-based syntax coloring. Coloring
is automatic and needs NO grammar changes; an optional wrapper handles composite spans.

- Role { ENUM, LITERAL, OPERATOR, IDENTIFIER } + Region(start, end, role).
- defaultRole(terminal): IntegerTerminal -> LITERAL; Literal/FlexibleLiteralChoice ->
  ENUM, or OPERATOR when all choices are punctuation (":", "+", "=", "~", "/", ...);
  RegexTerminal -> IDENTIFIER; whitespace/other -> uncoloured.
- Labeled(role, inner): optional, transparent wrapper. Matching is delegated to inner
  unchanged (SyntacticMatch/SemanticMatch/parse), so it affects only colour — e.g.
  Labeled(LITERAL, IPV4_ADDR) paints 127.0.0.1 as one literal instead of per-octet.
- Parse gains a defaulted `regions` field; the merging combinators (Seq, ZeroOrMore,
  OneOrMore, Repeat) thread it. colorize(value) returns labeled regions plus per-token
  defaults for anything not inside a labeled region.

Role -> TextAttributes mapping is deliberately left to the IntelliJ layer (next MR:
annotator + color settings, behind the experimental flag).

Tests: default roles; automatic colouring of the unchanged RestrictAddressFamilies
grammar (operator/enum, whitespace uncoloured); Labeled collapsing an IPv4 address to
one LITERAL; and Labeled being transparent to validation.

Refs #467 #342

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

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

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>

* docs: show an identifier example (Description=) in the color settings preview (#467 #342)

The color-settings preview had grammar examples for enum/literal/operator but none for
the Identifier role, so clicking "Value//Identifier (grammar)" highlighted nothing.
Tag the [Unit] Description= value (a config_parse_unit_string_printf identifier) so the
role has a visible example.

Refs #467 #342

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix: leave free-form string values at the default color (#467 #342)

The default heuristic mapped RegexTerminal -> IDENTIFIER, so free-form values like
Description= and interface names (Bond=) got recoloured, which felt wrong — those
should keep the editor's normal value color. Make RegexTerminal uncoloured by default.

- defaultRole: RegexTerminal now falls through to null (no coloring).
- Drop the Identifier descriptor + tag + demo example from the color settings page,
  since nothing uses the IDENTIFIER role by default now. The Role and its key are kept
  for grammars that opt in explicitly via Labeled later (e.g. a single-token User=).

Refs #467 #342

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* test: filter INFORMATION highlights from GrammarParseEngineInspectionTest

The value-color annotator adds INFORMATION-severity coloring highlights when the
experimental flag is on, which inflates doHighlighting() counts. Count only the
inspection problems (severity != INFORMATION), matching the value-coloring annotator.

* refactor: drop the unused Role.IDENTIFIER coloring role

IDENTIFIER was defined (enum value, GRAMMAR_IDENTIFIER attributes key, annotator
branch) but never produced: defaultRole never returns it, nothing wraps a value
in Labeled(Role.IDENTIFIER), and it has no color-settings descriptor. It was the
role intended for free-form names — but #483 settled that free-form values keep
the editor's default color, which leaves IDENTIFIER with no purpose. Remove it;
the taxonomy is ENUM / LITERAL / OPERATOR (plus uncoloured default).

---------

Co-authored-by: Steve Ramage <gitcommits@sjrx.net>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@SJrX

SJrX commented Jun 29, 2026

Copy link
Copy Markdown
Owner Author

Superseded by #497 (squash-merged into 242.x as a1daaf9), which bundled the value-coloring stack (#479 engine + #480 render + #482 preview + #483 free-form) re-cut against current 242.x. Closing.

@SJrX SJrX closed this Jun 29, 2026
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