Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
] @keyword

; `private`, `protected` and `public` are `Module` instance methods, not
; keywords: they can be called with arguments, passed a `def`, or shadowed.
; keywords. Bare, they parse as a plain identifier; `#is-not? local` keeps a
; local variable that shadows one of them from being highlighted as a call.
((identifier) @function.method.builtin
(#match? @function.method.builtin "^(private|protected|public)$"))
(#match? @function.method.builtin "^(private|protected|public)$")
(#is-not? local))

(constant) @constructor

Expand All @@ -50,6 +52,15 @@
((identifier) @function.method.builtin
(#eq? @function.method.builtin "require"))

; The argument forms, such as `private :foo` and `private def bar; end`, have to
; come after the general call pattern above to take precedence over it.
; `!receiver` keeps an unrelated method that happens to share the name, as in
; `acl.public`, highlighted as an ordinary call.
((call
!receiver
method: (identifier) @function.method.builtin)
(#match? @function.method.builtin "^(private|protected|public)$"))

; Function definitions

(alias (identifier) @function.method)
Expand Down
19 changes: 19 additions & 0 deletions test/highlight/classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,24 @@ def init(id)

protected
# ^ function.method.builtin

private :with_symbol
# <- function.method.builtin

private def with_def; end
# <- function.method.builtin

def shadowed
private = 1
# <- variable
private
# <- variable
private
end

def unrelated(acl)
acl.public
# ^ function.method
end
end
# <- keyword
Loading