Skip to content

Commit 067b152

Browse files
authored
Fix class constant highlighting (#107)
## 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: <img width="610" height="93" alt="image" src="https://github.com/user-attachments/assets/2502a452-4609-4b67-831a-ea1cdaf07513" /> <img width="468" height="165" alt="image" src="https://github.com/user-attachments/assets/115dc9a8-c636-4524-b12e-be55d5ccb884" />
1 parent 4bf9ddb commit 067b152

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

languages/php/highlights.scm

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
(nullsafe_member_access_expression
5151
name: (name) @property)
5252

53+
; Class constant access (e.g., Class::CONSTANT)
54+
55+
(class_constant_access_expression
56+
(_) (name) @constant)
57+
5358
; Special classes
5459

5560
(relative_scope) @constructor
@@ -64,14 +69,14 @@
6469

6570
; Variables
6671

72+
((name) @constructor
73+
(#match? @constructor "^[A-Z]"))
74+
6775
((name) @constant
6876
(#match? @constant "^_?[A-Z][A-Z\\d_]+$"))
6977
((name) @constant.builtin
7078
(#match? @constant.builtin "^__[A-Z][A-Z\d_]+__$"))
7179

72-
((name) @constructor
73-
(#match? @constructor "^[A-Z]"))
74-
7580
((name) @variable.builtin
7681
(#eq? @variable.builtin "this"))
7782

0 commit comments

Comments
 (0)