From 0c671895f74d0fe574b1d7506adbb400cdf7a618 Mon Sep 17 00:00:00 2001 From: Mark Tareshawty Date: Mon, 24 Aug 2026 01:44:21 -0400 Subject: [PATCH] highlights: treat private/protected/public as methods `private`, `protected` and `public` are `Module` instance methods, not keywords. They take arguments (`private :foo`), accept a `def` expression (`private def foo; end`), can be reached through `send`, and can be shadowed by a local variable. Highlighting them as `@keyword` made them read like `def` or `end` and diverged from how RubyMine and Ruby LSP render them. Capture them as `@function.method.builtin`, matching how this query already treats other well-known method calls such as `require` and `defined?`. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- queries/highlights.scm | 6 ++++-- test/highlight/classes.rb | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/queries/highlights.scm b/queries/highlights.scm index dd1c9139..3f308db0 100644 --- a/queries/highlights.scm +++ b/queries/highlights.scm @@ -33,8 +33,10 @@ "yield" ] @keyword -((identifier) @keyword - (#match? @keyword "^(private|protected|public)$")) +; `private`, `protected` and `public` are `Module` instance methods, not +; keywords: they can be called with arguments, passed a `def`, or shadowed. +((identifier) @function.method.builtin + (#match? @function.method.builtin "^(private|protected|public)$")) (constant) @constructor diff --git a/test/highlight/classes.rb b/test/highlight/classes.rb index f5aa258c..9139d903 100644 --- a/test/highlight/classes.rb +++ b/test/highlight/classes.rb @@ -22,12 +22,12 @@ def init(id) end private - # ^ keyword + # ^ function.method.builtin public - # ^ keyword + # ^ function.method.builtin protected - # ^ keyword + # ^ function.method.builtin end # <- keyword