Fix class constant highlighting#106
Closed
alfredomtx wants to merge 2 commits intozed-extensions:mainfrom
Closed
Conversation
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
9fc8fca to
eb6f5c7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
class_constant_access_expressionrule to correctly capture the constant name (e.g.,RESOURCE_RELATIONSinConversation::RESOURCE_RELATIONS) as@constant@constructorbefore@constantso UPPER_SNAKE_CASE names get@constantinstead of being overridden by the generic@constructorcatch-allProblem
Class constants accessed via
::(e.g.,Conversation::RESOURCE_RELATIONS) were highlighted as@constructor(same as class names) instead of@constant. This happened because:((name) @constructor (#match? @constructor "^[A-Z]"))pattern matched bothConversationandRESOURCE_RELATIONS@constantpattern, it overrode the constant highlightingFix
(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.@constructorbefore@constantso that for tokens matching both patterns,@constant(being last) wins.Verified with tree-sitter CLI
Screenshots: