Commit 067b152
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
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
53 | 58 | | |
54 | 59 | | |
55 | 60 | | |
| |||
64 | 69 | | |
65 | 70 | | |
66 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
67 | 75 | | |
68 | 76 | | |
69 | 77 | | |
70 | 78 | | |
71 | 79 | | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | 80 | | |
76 | 81 | | |
77 | 82 | | |
| |||
0 commit comments