Skip to content
Merged
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
126 changes: 63 additions & 63 deletions languages/ruby/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"and"
"end"
"in"
"not"
"or"
] @keyword

Expand Down Expand Up @@ -95,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
Expand All @@ -138,7 +116,7 @@
(encoding) @constant.builtin

(hash_splat_nil
"**" @operator) @constant.builtin
"nil" @constant.builtin)

(constant) @type

Expand Down Expand Up @@ -189,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
Expand All @@ -209,59 +195,70 @@

(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: (_) @_key @variable.parameter.keyword)
(pair
":" @variable.parameter.keyword)
])))))
(#eq? @_locals "locals")
(#not-eq? @_key ""))

; Regular comments (exclude RBS inline comments)
((comment) @comment
(#not-match? @comment "^\\s*#[:|]")
(#not-match? @comment "^\\s*#\\s*(@rbs|\\|)"))

; Operators
Comment thread
vitallium marked this conversation as resolved.
[
"!"
"~"
"+"
"-"
"**"
"*"
"/"
"%"
"<<"
">>"
"**"
"&"
"|"
"^"
">"
"<"
"<="
">="
"=="
"==="
"!="
"=~"
"!~"
"<=>"
"||"
"&&"
".."
"..."
"="
"**="
"*="
"/="
"%="
"+="
"-="
"<<="
">>="
"&&="
"&="
"||="
"|="
"^="
"=>"
"->"
(operator)
] @operator

(lambda
"->" @operator)

(singleton_class
"<<" @operator)

(superclass
"<" @operator)

(alternative_pattern
"|" @operator)

(conditional
"?" @operator
":" @operator)

(_
operator: _ @operator
(#not-any-of? @operator "and" "or" "not" "defined?" "." "::"))

Comment thread
AlternateRT marked this conversation as resolved.
[
","
";"
Expand All @@ -280,6 +277,9 @@
"%i("
] @punctuation.bracket

(block_parameters
"|" @punctuation.bracket)

Comment thread
AlternateRT marked this conversation as resolved.
(interpolation
"#{" @punctuation.special
"}" @punctuation.special) @embedded
14 changes: 13 additions & 1 deletion tests/erb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,17 @@ fn strict_local_names_share_parameter_highlighting() {
.map(|capture| capture.text.as_str())
.collect();

assert_eq!(parameters, ["title", "talks", "view_all_path", "subtitle"]);
assert_eq!(
parameters,
[
"title",
":",
"talks",
":",
"view_all_path",
":",
"subtitle",
":"
],
);
}
Loading
Loading