Skip to content

Commit c46690e

Browse files
authored
feat(ruby): Highlight instance vars, method defs, and keyword params distinctly (#298)
### Why Coming from VSCode/Cursor ecosystem, I really miss these semantic token modifiers: | Construct | Current capture | Shares its color with | |---|---|---| | Instance variables (`@foo`) | `@variable.special` | `self`, `super`, class variables | | Method definitions (`def foo`) | `@function.method` | every method **call** | | Keyword params (`def m(foo:)`) | `@variable.parameter` | positional parameters | These are exactly the distinctions many editors/themes expose (e.g. VS Code separates a method *declaration* from a method *call* via semantic token modifiers), but here the grammar collapses them, so the information needed to theme them is thrown away before it ever reaches the theme layer. `self`, `super`, and class variables intentionally stay on `@variable.special`; method calls stay on `@function.method`; positional params stay on `@variable.parameter`. ### Backwards compatibility This PR is purely **additive**: existing themes are unaffected, and theme authors gain three new opt-in targets. ### Consistency with existing conventions The new names follow the dotted sub-scoping already used throughout this file. ### How a theme author opts in ```jsonc // theme_overrides (or a theme's syntax map) "syntax": { "variable.special.instance": { "color": "#..." }, // @foo distinct from self/super "function.method.definition": { "color": "#..." }, // def name distinct from calls "variable.parameter.keyword": { "color": "#..." } // kwargs distinct from positional } ``` ### Screenshots #### Before <img width="354" height="690" alt="Screenshot 2026-06-23 at 23 50 06" src="https://github.com/user-attachments/assets/0f72ba9e-b424-4191-841c-646cc41f771f" /> #### After <img width="354" height="690" alt="Screenshot 2026-06-23 at 23 48 56" src="https://github.com/user-attachments/assets/f188764f-d360-4386-bd3c-4e92017cdc5d" />
1 parent 67c79df commit c46690e

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

languages/ruby/highlights.scm

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@
8181
name: [
8282
(identifier)
8383
(constant)
84-
] @function.method)
84+
] @function.method.definition)
8585

8686
(singleton_method
8787
name: [
8888
(identifier)
8989
(constant)
90-
] @function.method)
90+
] @function.method.definition)
9191

9292
(method_parameters
9393
[
@@ -98,7 +98,7 @@
9898
[
9999
name: (identifier)
100100
":"
101-
] @variable.parameter)
101+
] @variable.parameter.keyword)
102102
])
103103

104104
(block_parameters
@@ -138,10 +138,9 @@
138138

139139
(super) @variable.special
140140

141-
[
142-
(class_variable)
143-
(instance_variable)
144-
] @variable.special
141+
(class_variable) @variable.special
142+
143+
(instance_variable) @variable.special.instance
145144

146145
((call
147146
!receiver

0 commit comments

Comments
 (0)