From af609ada10ec34663280d8f59fa743ecbb324cbf Mon Sep 17 00:00:00 2001 From: AltCode Date: Sat, 19 Sep 2026 17:51:29 +0200 Subject: [PATCH 1/7] fix(ruby): adjust operator highlights 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 --- languages/ruby/highlights.scm | 49 ++++++++++++----------------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/languages/ruby/highlights.scm b/languages/ruby/highlights.scm index 690a5c7..8bb6f5e 100644 --- a/languages/ruby/highlights.scm +++ b/languages/ruby/highlights.scm @@ -53,6 +53,7 @@ "and" "end" "in" + "not" "or" ] @keyword @@ -137,8 +138,7 @@ (encoding) @constant.builtin -(hash_splat_nil - "**" @operator) @constant.builtin +(hash_splat_nil) @constant.builtin (constant) @type @@ -216,59 +216,39 @@ ; Operators [ - "!" - "~" - "+" - "-" - "**" + "?" "*" - "/" - "%" + "**" "<<" ">>" "&" "|" "^" - ">" "<" - "<=" - ">=" - "==" - "===" - "!=" - "=~" - "!~" - "<=>" - "||" - "&&" + ">" ".." "..." "=" - "**=" - "*=" - "/=" - "%=" - "+=" - "-=" - "<<=" - ">>=" - "&&=" - "&=" - "||=" - "|=" - "^=" "=>" "->" (operator) ] @operator +(_ + operator: _ @operator + (#not-any-of? @operator "and" "or" "not" "defined?")) + [ "," ";" "." + ":" "::" ] @punctuation.delimiter +(conditional + ":" @operator) + [ "(" ")" @@ -280,6 +260,9 @@ "%i(" ] @punctuation.bracket +(block_parameters + "|" @punctuation.bracket) + (interpolation "#{" @punctuation.special "}" @punctuation.special) @embedded From c11450c4eed9874b0a07b5563cb7d4fd20aea758 Mon Sep 17 00:00:00 2001 From: AltCode Date: Mon, 21 Sep 2026 20:25:01 +0200 Subject: [PATCH 2/7] Fully scope `|` token captures --- languages/ruby/highlights.scm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/languages/ruby/highlights.scm b/languages/ruby/highlights.scm index 8bb6f5e..39de031 100644 --- a/languages/ruby/highlights.scm +++ b/languages/ruby/highlights.scm @@ -222,7 +222,6 @@ "<<" ">>" "&" - "|" "^" "<" ">" @@ -234,6 +233,9 @@ (operator) ] @operator +(alternative_pattern + "|" @operator) + (_ operator: _ @operator (#not-any-of? @operator "and" "or" "not" "defined?")) From 93112240944551cd81bb6c2b13fcf925ee50ab5b Mon Sep 17 00:00:00 2001 From: AltCode Date: Mon, 21 Sep 2026 20:25:52 +0200 Subject: [PATCH 3/7] Limit operator capture for `.` and `::` as well --- languages/ruby/highlights.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/languages/ruby/highlights.scm b/languages/ruby/highlights.scm index 39de031..c36d0b4 100644 --- a/languages/ruby/highlights.scm +++ b/languages/ruby/highlights.scm @@ -238,7 +238,7 @@ (_ operator: _ @operator - (#not-any-of? @operator "and" "or" "not" "defined?")) + (#not-any-of? @operator "and" "or" "not" "defined?" "." "::")) [ "," From de5d3f5997d957b97bfe72524b2130d0fe38ae08 Mon Sep 17 00:00:00 2001 From: AltCode Date: Mon, 21 Sep 2026 20:29:50 +0200 Subject: [PATCH 4/7] Fully scope conditional operator captures --- languages/ruby/highlights.scm | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/languages/ruby/highlights.scm b/languages/ruby/highlights.scm index c36d0b4..7d71baa 100644 --- a/languages/ruby/highlights.scm +++ b/languages/ruby/highlights.scm @@ -216,7 +216,6 @@ ; Operators [ - "?" "*" "**" "<<" @@ -236,6 +235,10 @@ (alternative_pattern "|" @operator) +(conditional + "?" @operator + ":" @operator) + (_ operator: _ @operator (#not-any-of? @operator "and" "or" "not" "defined?" "." "::")) @@ -244,13 +247,9 @@ "," ";" "." - ":" "::" ] @punctuation.delimiter -(conditional - ":" @operator) - [ "(" ")" From ea5afc72824b4d79495442c1626e83d33d8055d3 Mon Sep 17 00:00:00 2001 From: AltCode Date: Mon, 21 Sep 2026 23:03:55 +0200 Subject: [PATCH 5/7] Fully scope `->`, `<<`, and `<` token captures And remove bare captures for `>>` and `>` that are already covered by the `(_ operator: _ @operator)` capture --- languages/ruby/highlights.scm | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/languages/ruby/highlights.scm b/languages/ruby/highlights.scm index 7d71baa..4dc19e9 100644 --- a/languages/ruby/highlights.scm +++ b/languages/ruby/highlights.scm @@ -218,20 +218,24 @@ [ "*" "**" - "<<" - ">>" "&" "^" - "<" - ">" ".." "..." "=" "=>" - "->" (operator) ] @operator +(lambda + "->" @operator) + +(singleton_class + "<<" @operator) + +(superclass + "<" @operator) + (alternative_pattern "|" @operator) From c2f367351c656d7236972d68ec662ce9a07b1d14 Mon Sep 17 00:00:00 2001 From: AltCode Date: Mon, 21 Sep 2026 23:11:24 +0200 Subject: [PATCH 6/7] Adjust `hash_splat_nil` capture --- languages/ruby/highlights.scm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/languages/ruby/highlights.scm b/languages/ruby/highlights.scm index 4dc19e9..362fc99 100644 --- a/languages/ruby/highlights.scm +++ b/languages/ruby/highlights.scm @@ -138,7 +138,8 @@ (encoding) @constant.builtin -(hash_splat_nil) @constant.builtin +(hash_splat_nil + "nil" @constant.builtin) (constant) @type From 864b76862bb38f4ce2fec99839be7e5e18f21d08 Mon Sep 17 00:00:00 2001 From: AltCode Date: Mon, 21 Sep 2026 23:41:22 +0200 Subject: [PATCH 7/7] Fully scope `:` token captures Also ensure that the highlights for `keyword_parameter` are applied when the node appears inside a `lambda_parameters` or `block_parameters` node, and adjust the highlight of delimited hash key symbols, which is a `string` node whose parent is either `pair` or `keyword_pattern` --- languages/ruby/highlights.scm | 59 ++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/languages/ruby/highlights.scm b/languages/ruby/highlights.scm index 362fc99..e041409 100644 --- a/languages/ruby/highlights.scm +++ b/languages/ruby/highlights.scm @@ -96,37 +96,14 @@ (identifier) @variable.parameter (optional_parameter name: (identifier) @variable.parameter) - (keyword_parameter - [ - name: (identifier) - ":" - ] @variable.parameter.keyword) ]) (block_parameters (identifier) @variable.parameter) -; ERB strict locals are injected as Ruby, but their parameter list is not a -; valid standalone Ruby program. Match the parser's recovery shape so the -; first required local and the remaining keyword locals are highlighted alike. -((call - method: (identifier) @_locals - arguments: (argument_list - (parenthesized_statements - (call - method: (identifier) @variable.parameter.keyword)))) - (#eq? @_locals "locals")) - -((call - method: (identifier) @_locals - arguments: (argument_list - (parenthesized_statements - (call - arguments: (argument_list - (pair - key: (hash_key_symbol) @variable.parameter.keyword)))))) - (#eq? @_locals "locals") - (#not-eq? @variable.parameter.keyword "")) +(keyword_parameter + name: (identifier) @variable.parameter.keyword + ":" @variable.parameter.keyword) ; Identifiers ((identifier) @constant.builtin @@ -190,6 +167,14 @@ (bare_symbol) ] @string.special.symbol +(pair + key: (_) @string.special.symbol + ":" @string.special.symbol) + +(keyword_pattern + key: (_) @string.special.symbol + ":" @string.special.symbol) + (regex) @string.regex (escape_sequence) @string.escape @@ -210,6 +195,28 @@ (nil) @constant.builtin +; ERB strict locals are injected as Ruby, but their parameter list is not a +; valid standalone Ruby program. Match the parser's recovery shape so the +; first required local and the remaining keyword locals are highlighted alike. +((call + method: (identifier) @_locals + arguments: (argument_list + (parenthesized_statements + (call + method: (identifier) @variable.parameter.keyword)))) + (#eq? @_locals "locals")) + +((call + method: (identifier) @_locals + arguments: (argument_list + (parenthesized_statements + (call + arguments: (argument_list + (pair + key: (_) @variable.parameter.keyword + ":" @variable.parameter.keyword)))))) + (#eq? @_locals "locals")) + ; Regular comments (exclude RBS inline comments) ((comment) @comment (#not-match? @comment "^\\s*#[:|]")