Skip to content

Conversation

@skipkayhil
Copy link
Contributor

Previously, when trying to highlight the definition of the comparable method (aka the spaceship, <=>), the < would be highlighted as Name::Function but the => would be Operator. This happens because of the ordering of potential matches in the funcname regular expression:

%r(
  # snip
  <<? | >>? | <=>? # snip
)

The method name is always caught by the single < match, and so never makes it to the <=> possibility.

This commit fixes the issue by trying to match <=>? before <<?. This ensures it can be matched, and since none of the following potential matches are a superset of its (<=>?) matches it won't cause any issue with subsequent possibilities.

Previously, when trying to highlight the definition of the comparable
method (aka the spaceship, `<=>`), the `<` would be highlighted as
`Name::Function` but the `=>` would be `Operator`. This happens because
of the ordering of potential matches in the `funcname` regular
expression:

```ruby
%r(
  # snip
  <<? | >>? | <=>? # snip
)
```

The method name is always caught by the single `<` match, and so never
makes it to the `<=>` possibility.

This commit fixes the issue by trying to match `<=>?` before `<<?`. This
ensures it _can_ be matched, and since none of the following potential
matches are a superset of its (`<=>?`) matches it won't cause any issue
with subsequent possibilities.
@tancnle
Copy link
Collaborator

tancnle commented Aug 5, 2025

Thanks, @skipkayhil. LGTM.

@tancnle tancnle added this pull request to the merge queue Aug 5, 2025
Merged via the queue into rouge-ruby:master with commit 327071f Aug 5, 2025
9 checks passed
@skipkayhil skipkayhil deleted the hm-xmlqwyxlnsltwlqr branch August 5, 2025 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants