Skip to content

Commit

Permalink
feat: correct Swift highlights (#12409)
Browse files Browse the repository at this point in the history
- Adds injections for the `comment` language
- Correct highlight of the `nil` value. Same highlight as `null` in javascript, java and others
- Recognize `<` and `>` as punctuation, used in generics (same color as the syntax used in other languages)
- `protocol` function methods are recognized
- When accessing object properties, like `hello.world`, the `world` is properly recognized as being a member
- Recognize the `\` as an operator
  • Loading branch information
NikitaRevenco authored Jan 5, 2025
1 parent eed052e commit 2b8f8df
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 7 additions & 2 deletions runtime/queries/swift/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
["\\(" ")"] @punctuation.special)

["." ";" ":" "," ] @punctuation.delimiter
["(" ")" "[" "]" "{" "}"] @punctuation.bracket
["(" ")" "[" "]" "{" "}" "<" ">"] @punctuation.bracket

; Identifiers
(attribute) @variable
Expand All @@ -24,6 +24,7 @@
] @keyword

(function_declaration (simple_identifier) @function.method)
(protocol_function_declaration (simple_identifier) @function.method)
(init_declaration ["init" @constructor])
(deinit_declaration ["deinit" @constructor])

Expand Down Expand Up @@ -91,6 +92,9 @@
(#match? @type "^[A-Z]"))
(call_expression (simple_identifier) @keyword (#eq? @keyword "defer")) ; defer { ... }

(navigation_suffix
(simple_identifier) @variable.other.member)

(try_operator) @operator
(try_operator ["try" @keyword])

Expand Down Expand Up @@ -147,7 +151,7 @@
(integer_literal) @constant.numeric.integer
(real_literal) @constant.numeric.float
(boolean_literal) @constant.builtin.boolean
"nil" @variable.builtin
"nil" @constant.builtin

"?" @type
(type_annotation "!" @type)
Expand All @@ -160,6 +164,7 @@
"?"
"+"
"-"
"\\"
"*"
"/"
"%"
Expand Down
4 changes: 4 additions & 0 deletions runtime/queries/swift/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@

((regex_literal) @injection.content
(#set! injection.language "regex"))

((comment) @injection.content
(#set! injection.language "comment")
(#set! injection.include-children))

0 comments on commit 2b8f8df

Please sign in to comment.