feat(swift): add many missing highlights

This commit is contained in:
Riley Bruins 2024-09-17 14:33:30 -07:00 committed by Christian Clason
parent 45ee50d02b
commit 12e339e370

View file

@ -5,9 +5,7 @@
"," ","
] @punctuation.delimiter ] @punctuation.delimiter
; TODO: "\\(" ")" in interpolations should be @punctuation.special
[ [
"\\("
"(" "("
")" ")"
"[" "["
@ -17,14 +15,18 @@
] @punctuation.bracket ] @punctuation.bracket
; Identifiers ; Identifiers
(attribute) @variable
(type_identifier) @type (type_identifier) @type
(self_expression) @variable.builtin [
(self_expression)
(super_expression)
] @variable.builtin
; Declarations ; Declarations
"func" @keyword.function [
"func"
"deinit"
] @keyword.function
[ [
(visibility_modifier) (visibility_modifier)
@ -36,16 +38,17 @@
(mutation_modifier) (mutation_modifier)
] @keyword.modifier ] @keyword.modifier
(simple_identifier) @variable
(function_declaration (function_declaration
(simple_identifier) @function.method) (simple_identifier) @function.method)
(protocol_function_declaration
name: (simple_identifier) @function.method)
(init_declaration (init_declaration
"init" @constructor) "init" @constructor)
(throws) @keyword
(where_keyword) @keyword
(parameter (parameter
external_name: (simple_identifier) @variable.parameter) external_name: (simple_identifier) @variable.parameter)
@ -63,9 +66,6 @@
(identifier (identifier
(simple_identifier) @variable.parameter)) (simple_identifier) @variable.parameter))
(pattern
bound_identifier: (simple_identifier)) @variable
[ [
"protocol" "protocol"
"extension" "extension"
@ -80,6 +80,16 @@
"unowned" "unowned"
"didSet" "didSet"
"willSet" "willSet"
"subscript"
"let"
"var"
(throws)
(where_keyword)
(getter_specifier)
(setter_specifier)
(modify_specifier)
(else)
(as_operator)
] @keyword ] @keyword
[ [
@ -94,12 +104,6 @@
"await" "await"
] @keyword.coroutine ] @keyword.coroutine
[
(getter_specifier)
(setter_specifier)
(modify_specifier)
] @keyword
(shebang_line) @keyword.directive (shebang_line) @keyword.directive
(class_body (class_body
@ -116,7 +120,8 @@
(simple_identifier) @variable.member)) (simple_identifier) @variable.member))
(value_argument (value_argument
name: (value_argument_label) @variable.member) name: (value_argument_label
(simple_identifier) @variable.member))
(import_declaration (import_declaration
"import" @keyword.import) "import" @keyword.import)
@ -124,14 +129,11 @@
(enum_entry (enum_entry
"case" @keyword) "case" @keyword)
; Attributes
(modifiers
(attribute) @attribute.builtin)
(modifiers (modifiers
(attribute (attribute
"@" @attribute
(user_type (user_type
(type_identifier) @attribute.builtin))) (type_identifier) @attribute)))
; Function calls ; Function calls
(call_expression (call_expression
@ -151,9 +153,30 @@
(simple_identifier) @type) ; SomeType.method(): highlight SomeType as a type (simple_identifier) @type) ; SomeType.method(): highlight SomeType as a type
(#lua-match? @type "^[A-Z]")) (#lua-match? @type "^[A-Z]"))
(directive) @function.macro (directive) @keyword.directive
(diagnostic) @function.macro ; See https://docs.swift.org/swift-book/documentation/the-swift-programming-language/lexicalstructure/#Keywords-and-Punctuation
[
(diagnostic)
"#available"
"#unavailable"
"#fileLiteral"
"#colorLiteral"
"#imageLiteral"
"#keyPath"
"#selector"
"#externalMacro"
] @function.macro
[
"#column"
"#dsohandle"
"#fileID"
"#filePath"
"#file"
"#function"
"#line"
] @constant.macro
; Statements ; Statements
(for_statement (for_statement
@ -162,13 +185,6 @@
(for_statement (for_statement
"in" @keyword.repeat) "in" @keyword.repeat)
(for_statement
(pattern) @variable)
(else) @keyword
(as_operator) @keyword
[ [
"while" "while"
"repeat" "repeat"
@ -176,11 +192,6 @@
"break" "break"
] @keyword.repeat ] @keyword.repeat
[
"let"
"var"
] @keyword
(guard_statement (guard_statement
"guard" @keyword.conditional) "guard" @keyword.conditional)
@ -205,13 +216,14 @@
[ [
"?" "?"
":" ":"
] @keyword.conditional) ] @keyword.conditional.ternary)
[ [
(try_operator)
"do" "do"
(throw_keyword) (throw_keyword)
(catch_keyword) (catch_keyword)
] @keyword ] @keyword.exception
(statement_label) @label (statement_label) @label
@ -233,7 +245,7 @@
; String literals ; String literals
(line_str_text) @string (line_str_text) @string
(str_escaped_char) @string (str_escaped_char) @string.escape
(multi_line_str_text) @string (multi_line_str_text) @string
@ -241,7 +253,23 @@
(raw_str_end_part) @string (raw_str_end_part) @string
(raw_str_interpolation_start) @punctuation.special (line_string_literal
[
"\\("
")"
] @punctuation.special)
(multi_line_string_literal
[
"\\("
")"
] @punctuation.special)
(raw_str_interpolation
[
(raw_str_interpolation_start)
")"
] @punctuation.special)
[ [
"\"" "\""
@ -266,6 +294,8 @@
"nil" @constant.builtin "nil" @constant.builtin
(wildcard_pattern) @character.special
; Regex literals ; Regex literals
(regex_literal) @string.regexp (regex_literal) @string.regexp
@ -273,9 +303,6 @@
(custom_operator) @operator (custom_operator) @operator
[ [
"try"
"try?"
"try!"
"+" "+"
"-" "-"
"*" "*"
@ -288,10 +315,13 @@
"/=" "/="
"<" "<"
">" ">"
"<<"
">>"
"<=" "<="
">=" ">="
"++" "++"
"--" "--"
"^"
"&" "&"
"&&" "&&"
"|" "|"
@ -302,9 +332,16 @@
"!==" "!=="
"==" "=="
"===" "==="
"?"
"??" "??"
"->" "->"
"..<" "..<"
"..." "..."
(bang) (bang)
] @operator ] @operator
(type_arguments
[
"<"
">"
] @punctuation.bracket)