Skip to content

Commit

Permalink
Highlight Self and defer appropriately
Browse files Browse the repository at this point in the history
Adds special case `#eq?` clauses into the highlight queries for special
cases where we have keywords or builtins that aren't in the grammar.

Specifically:
* With `Self`, this is parsed as a boring type identifier, but should be
  highlighted as a builtin variable.
* With `defer { }`, this is parsed as a function, but the behavior is
  unique enough that it is reasonable to present it as a keyword.
  • Loading branch information
alex-pinkus committed Mar 4, 2024
1 parent 4b5c54b commit 5ba552f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
(attribute) @variable
(type_identifier) @type
(self_expression) @variable.builtin
(user_type (type_identifier) @variable.builtin (#eq? @variable.builtin "Self"))

; Declarations
"func" @keyword.function
Expand Down Expand Up @@ -69,6 +70,7 @@
((navigation_expression
(simple_identifier) @type) ; SomeType.method(): highlight SomeType as a type
(#match? @type "^[A-Z]"))
(call_expression (simple_identifier) @keyword (#eq? @keyword "defer")) ; defer { ... }

(try_operator) @operator
(try_operator ["try" @keyword])
Expand Down Expand Up @@ -168,4 +170,3 @@
"..<"
"..."
] @operator

0 comments on commit 5ba552f

Please sign in to comment.