Skip to content

Comments

Fix class constant highlighting#106

Closed
alfredomtx wants to merge 2 commits intozed-extensions:mainfrom
alfredomtx:feat/class-constant-highlighting
Closed

Fix class constant highlighting#106
alfredomtx wants to merge 2 commits intozed-extensions:mainfrom
alfredomtx:feat/class-constant-highlighting

Conversation

@alfredomtx
Copy link
Contributor

@alfredomtx alfredomtx commented Feb 16, 2026

Summary

  • Add explicit class_constant_access_expression rule to correctly capture the constant name (e.g., RESOURCE_RELATIONS in Conversation::RESOURCE_RELATIONS) as @constant
  • Reorder @constructor before @constant so UPPER_SNAKE_CASE names get @constant instead of being overridden by the generic @constructor catch-all

Problem

Class constants accessed via :: (e.g., Conversation::RESOURCE_RELATIONS) were highlighted as @constructor (same as class names) instead of @constant. This happened because:

  1. The generic ((name) @constructor (#match? @constructor "^[A-Z]")) pattern matched both Conversation and RESOURCE_RELATIONS
  2. Since it appeared after the @constant pattern, it overrode the constant highlighting

Fix

  1. New rule: (class_constant_access_expression (_) (name) @constant) — explicitly captures the constant name within :: access expressions. Uses positional matching since this AST node has no named fields.
  2. Reorder: Move @constructor before @constant so that for tokens matching both patterns, @constant (being last) wins.

Verified with tree-sitter CLI

Conversation     → @constructor ✓
RESOURCE_RELATIONS → @constant ✓
MAX_VALUE        → @constant ✓
PHP_INT_MAX      → @constant ✓
self             → @constructor ✓

Screenshots:

image image

@cla-bot cla-bot bot added the cla-signed label Feb 16, 2026
Two changes:
- Add explicit rule for class_constant_access_expression to capture
  the constant name as @constant
- Reorder @constructor before @constant so that UPPER_SNAKE_CASE names
  (like RESOURCE_RELATIONS, PHP_INT_MAX) correctly get @constant instead
  of being overridden by the generic @constructor catch-all
@alfredomtx alfredomtx force-pushed the feat/class-constant-highlighting branch from 9fc8fca to eb6f5c7 Compare February 16, 2026 22:46
@alfredomtx alfredomtx closed this Feb 16, 2026
@alfredomtx alfredomtx reopened this Feb 16, 2026
@alfredomtx alfredomtx closed this Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant