Skip to content

fix(ruby): adjust operator highlights - #338

Open
AlternateRT wants to merge 1 commit into
zed-extensions:mainfrom
AlternateRT:adjust-operator-highlights
Open

AlternateRT wants to merge 1 commit into
zed-extensions:mainfrom
AlternateRT:adjust-operator-highlights

Conversation

@AlternateRT

@AlternateRT AlternateRT commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Stop capturing most of these from just the bare token and instead capture them when defined in the operator: field

The previous way erroneously highlighted some of them as operator when used elsewhere - e.g. / and | are also used as delimiters for the regex literal and block parameters respectively

Also adds some missing highlights for the not, ?, and : operators

@cla-bot cla-bot Bot added the cla-signed label Sep 19, 2026
@AlternateRT
AlternateRT force-pushed the adjust-operator-highlights branch from de01586 to 6f1a85a Compare September 19, 2026 16:26
Stop capturing most of these from just the bare token and instead
capture them when defined in the `operator:` field

The previous way erroneously highlighted some of them as operator when
used elsewhere - e.g. `/` and `|` are also used as delimiters for the
regex literal and block parameters respectively

Also adds some missing highlights for the `not`, `?`, and `:` operators
@AlternateRT
AlternateRT force-pushed the adjust-operator-highlights branch from 6f1a85a to af609ad Compare September 19, 2026 16:28

@vitallium vitallium left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I left some questions and suggestions. Additionally, it would be nice to add some regression tests to ensure that the changes introduced in this MR aren't broken by future changes.

Thanks!

","
";"
"."
":"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (blocking): This capture replaces the earlier keyword parameter capture.

For valid Ruby such as:

def m(kw:, kw2: 3); end

the existing rule captures kw: as @variable.parameter.keyword, but this later pattern recaptures : as @punctuation.delimiter. Zed gives the later capture precedence, so the parameter name and colon now render differently.

could we scope punctuation colons to contexts where they are separators instead, for example?

@@ -216,59 +216,39 @@

; Operators

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: Not sure that just removing operators here is a good idea. For example, removing the bare - capture loses highlighting during parser recovery:

def maximum = 5
def consumed = 3
def remaining = maximum &.- consumed

TS places the operator call in an ERROR recovery node (and this is the upstream issue). That node has no usable operator: field for -.

I'd rather scope down operators first with overrides. We can check what Helix does.

(_
operator: _ @operator
(#not-any-of? @operator "and" "or" "not" "defined?"))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Should &. use @operator? I'd say, yes.

this pattern matches the operator: field of every call node, like:

obj.foo
obj::foo
obj&.foo

The punctuation rule below replaces the captures for . and ::. It does not replace the capture for &.. Probably we need to limit that here.


(block_parameters
"|" @punctuation.bracket)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: I think we need to match | only where it is an operator actually. For example,

[1].each { |item| item }

The rule on line 217 first marks block parameter pipes as operators. A this rule then replaces that result. I'd check if we can do smth like this here:

(alternative_pattern
  "|" @operator)

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.

2 participants