summaryrefslogtreecommitdiffstats
path: root/queries
diff options
context:
space:
mode:
authorRiley Bruins <ribru17@hotmail.com>2024-09-17 14:33:30 -0700
committerChristian Clason <c.clason@uni-graz.at>2024-09-19 08:43:44 +0200
commit12e339e370aa7c7ec8a57579425dd5d95a309b7e (patch)
tree07eeae5cef172b84d2b681125a88fb1db7bb2377 /queries
parentfeat(htmldjango): improve punctuation highlighting (diff)
downloadnvim-treesitter-12e339e370aa7c7ec8a57579425dd5d95a309b7e.tar
nvim-treesitter-12e339e370aa7c7ec8a57579425dd5d95a309b7e.tar.gz
nvim-treesitter-12e339e370aa7c7ec8a57579425dd5d95a309b7e.tar.bz2
nvim-treesitter-12e339e370aa7c7ec8a57579425dd5d95a309b7e.tar.lz
nvim-treesitter-12e339e370aa7c7ec8a57579425dd5d95a309b7e.tar.xz
nvim-treesitter-12e339e370aa7c7ec8a57579425dd5d95a309b7e.tar.zst
nvim-treesitter-12e339e370aa7c7ec8a57579425dd5d95a309b7e.zip
feat(swift): add many missing highlights
Diffstat (limited to 'queries')
-rw-r--r--queries/swift/highlights.scm129
1 files changed, 83 insertions, 46 deletions
diff --git a/queries/swift/highlights.scm b/queries/swift/highlights.scm
index 562be5e33..5c52ee9d6 100644
--- a/queries/swift/highlights.scm
+++ b/queries/swift/highlights.scm
@@ -5,9 +5,7 @@
","
] @punctuation.delimiter
-; TODO: "\\(" ")" in interpolations should be @punctuation.special
[
- "\\("
"("
")"
"["
@@ -17,14 +15,18 @@
] @punctuation.bracket
; Identifiers
-(attribute) @variable
-
(type_identifier) @type
-(self_expression) @variable.builtin
+[
+ (self_expression)
+ (super_expression)
+] @variable.builtin
; Declarations
-"func" @keyword.function
+[
+ "func"
+ "deinit"
+] @keyword.function
[
(visibility_modifier)
@@ -36,16 +38,17 @@
(mutation_modifier)
] @keyword.modifier
+(simple_identifier) @variable
+
(function_declaration
(simple_identifier) @function.method)
+(protocol_function_declaration
+ name: (simple_identifier) @function.method)
+
(init_declaration
"init" @constructor)
-(throws) @keyword
-
-(where_keyword) @keyword
-
(parameter
external_name: (simple_identifier) @variable.parameter)
@@ -63,9 +66,6 @@
(identifier
(simple_identifier) @variable.parameter))
-(pattern
- bound_identifier: (simple_identifier)) @variable
-
[
"protocol"
"extension"
@@ -80,6 +80,16 @@
"unowned"
"didSet"
"willSet"
+ "subscript"
+ "let"
+ "var"
+ (throws)
+ (where_keyword)
+ (getter_specifier)
+ (setter_specifier)
+ (modify_specifier)
+ (else)
+ (as_operator)
] @keyword
[
@@ -94,12 +104,6 @@
"await"
] @keyword.coroutine
-[
- (getter_specifier)
- (setter_specifier)
- (modify_specifier)
-] @keyword
-
(shebang_line) @keyword.directive
(class_body
@@ -116,7 +120,8 @@
(simple_identifier) @variable.member))
(value_argument
- name: (value_argument_label) @variable.member)
+ name: (value_argument_label
+ (simple_identifier) @variable.member))
(import_declaration
"import" @keyword.import)
@@ -124,14 +129,11 @@
(enum_entry
"case" @keyword)
-; Attributes
-(modifiers
- (attribute) @attribute.builtin)
-
(modifiers
(attribute
+ "@" @attribute
(user_type
- (type_identifier) @attribute.builtin)))
+ (type_identifier) @attribute)))
; Function calls
(call_expression
@@ -151,9 +153,30 @@
(simple_identifier) @type) ; SomeType.method(): highlight SomeType as a type
(#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
(for_statement
@@ -162,13 +185,6 @@
(for_statement
"in" @keyword.repeat)
-(for_statement
- (pattern) @variable)
-
-(else) @keyword
-
-(as_operator) @keyword
-
[
"while"
"repeat"
@@ -176,11 +192,6 @@
"break"
] @keyword.repeat
-[
- "let"
- "var"
-] @keyword
-
(guard_statement
"guard" @keyword.conditional)
@@ -205,13 +216,14 @@
[
"?"
":"
- ] @keyword.conditional)
+ ] @keyword.conditional.ternary)
[
+ (try_operator)
"do"
(throw_keyword)
(catch_keyword)
-] @keyword
+] @keyword.exception
(statement_label) @label
@@ -233,7 +245,7 @@
; String literals
(line_str_text) @string
-(str_escaped_char) @string
+(str_escaped_char) @string.escape
(multi_line_str_text) @string
@@ -241,7 +253,23 @@
(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
+(wildcard_pattern) @character.special
+
; Regex literals
(regex_literal) @string.regexp
@@ -273,9 +303,6 @@
(custom_operator) @operator
[
- "try"
- "try?"
- "try!"
"+"
"-"
"*"
@@ -288,10 +315,13 @@
"/="
"<"
">"
+ "<<"
+ ">>"
"<="
">="
"++"
"--"
+ "^"
"&"
"&&"
"|"
@@ -302,9 +332,16 @@
"!=="
"=="
"==="
+ "?"
"??"
"->"
"..<"
"..."
(bang)
] @operator
+
+(type_arguments
+ [
+ "<"
+ ">"
+ ] @punctuation.bracket)