Skip to content

Comments

Fix class constant highlighting#107

Open
alfredomtx wants to merge 1 commit intozed-extensions:mainfrom
alfredomtx:fix/class-constant-highlight
Open

Fix class constant highlighting#107
alfredomtx wants to merge 1 commit intozed-extensions:mainfrom
alfredomtx:fix/class-constant-highlight

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 Class::CONSTANT) 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

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
@cla-bot cla-bot bot added the cla-signed label Feb 16, 2026
@alfredomtx
Copy link
Contributor Author

alfredomtx commented Feb 16, 2026

Fixes item 1 of issue #81

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