fix(ruby): adjust operator highlights - #338
AlternateRT wants to merge 1 commit into
Conversation
de01586 to
6f1a85a
Compare
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
6f1a85a to
af609ad
Compare
vitallium
left a comment
There was a problem hiding this comment.
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!
| "," | ||
| ";" | ||
| "." | ||
| ":" |
There was a problem hiding this comment.
issue (blocking): This capture replaces the earlier keyword parameter capture.
For valid Ruby such as:
def m(kw:, kw2: 3); endthe 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 | |||
There was a problem hiding this comment.
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 &.- consumedTS 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?")) | ||
|
|
There was a problem hiding this comment.
question: Should &. use @operator? I'd say, yes.
this pattern matches the operator: field of every call node, like:
obj.foo
obj::foo
obj&.fooThe 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) | ||
|
|
There was a problem hiding this comment.
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)
Stop capturing most of these from just the bare token and instead capture them when defined in the
operator:fieldThe 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 respectivelyAlso adds some missing highlights for the
not,?, and:operators