helix-mirror/runtime/queries/swift/highlights.scm

197 lines
4.3 KiB
Scheme
Raw Normal View History

; Upstream: https://github.com/alex-pinkus/tree-sitter-swift/blob/57c1c6d6ffa1c44b330182d41717e6fe37430704/queries/highlights.scm
2022-08-17 05:40:21 +04:00
(line_string_literal
["\\(" ")"] @punctuation.special)
["." ";" ":" "," ] @punctuation.delimiter
["(" ")" "[" "]" "{" "}"] @punctuation.bracket
2022-04-08 22:10:37 +04:00
; Identifiers
(attribute) @variable
(type_identifier) @type
(self_expression) @variable.builtin
(user_type (type_identifier) @variable.builtin (#eq? @variable.builtin "Self"))
2022-04-08 22:10:37 +04:00
; Declarations
"func" @keyword.function
[
(visibility_modifier)
(member_modifier)
(function_modifier)
(property_modifier)
(parameter_modifier)
(inheritance_modifier)
] @keyword
(function_declaration (simple_identifier) @function.method)
(init_declaration ["init" @constructor])
(deinit_declaration ["deinit" @constructor])
2022-04-08 22:10:37 +04:00
(throws) @keyword
"async" @keyword
"await" @keyword
2022-04-08 22:10:37 +04:00
(where_keyword) @keyword
(parameter external_name: (simple_identifier) @variable.parameter)
(parameter name: (simple_identifier) @variable.parameter)
(type_parameter (type_identifier) @variable.parameter)
(inheritance_constraint (identifier (simple_identifier) @variable.parameter))
(equality_constraint (identifier (simple_identifier) @variable.parameter))
2022-08-17 05:40:21 +04:00
(pattern bound_identifier: (simple_identifier)) @variable
2022-04-08 22:10:37 +04:00
[
"typealias"
"struct"
"class"
2022-08-17 05:40:21 +04:00
"actor"
2022-04-08 22:10:37 +04:00
"enum"
"protocol"
"extension"
"indirect"
2022-08-17 05:40:21 +04:00
"nonisolated"
"override"
"convenience"
"required"
"mutating"
"associatedtype"
"package"
"any"
2022-04-08 22:10:37 +04:00
] @keyword
(opaque_type ["some" @keyword])
(existential_type ["any" @keyword])
(precedence_group_declaration
["precedencegroup" @keyword]
(simple_identifier) @type)
(precedence_group_attribute
(simple_identifier) @keyword
[(simple_identifier) @type
(boolean_literal) @constant.builtin.boolean])
2022-04-08 22:10:37 +04:00
[
(getter_specifier)
(setter_specifier)
(modify_specifier)
] @keyword
2022-08-17 05:40:21 +04:00
(class_body (property_declaration (pattern (simple_identifier) @variable.other.member)))
(protocol_property_declaration (pattern (simple_identifier) @variable.other.member))
2022-04-08 22:10:37 +04:00
2022-08-17 05:40:21 +04:00
(import_declaration "import" @keyword.control.import)
2022-04-08 22:10:37 +04:00
2022-08-17 05:40:21 +04:00
(enum_entry "case" @keyword)
2022-04-08 22:10:37 +04:00
; Function calls
(call_expression (simple_identifier) @function) ; foo()
(call_expression ; foo.bar.baz(): highlight the baz()
(navigation_expression
(navigation_suffix (simple_identifier) @function)))
((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])
2022-04-08 22:10:37 +04:00
(directive) @function.macro
(diagnostic) @function.macro
; Statements
2022-08-17 05:40:21 +04:00
(for_statement "for" @keyword.control.repeat)
(for_statement "in" @keyword.control.repeat)
2022-04-08 22:10:37 +04:00
(for_statement item: (simple_identifier) @variable)
(else) @keyword
(as_operator) @keyword
["while" "repeat" "continue" "break"] @keyword.control.repeat
["let" "var"] @keyword
2022-08-17 05:40:21 +04:00
(guard_statement "guard" @keyword.control.conditional)
(if_statement "if" @keyword.control.conditional)
(switch_statement "switch" @keyword.control.conditional)
(switch_entry "case" @keyword)
(switch_entry "fallthrough" @keyword)
2022-04-08 22:10:37 +04:00
(switch_entry (default_keyword) @keyword)
2022-08-17 05:40:21 +04:00
"return" @keyword.return
2022-04-08 22:10:37 +04:00
(ternary_expression
["?" ":"] @keyword.control.conditional)
["do" (throw_keyword) (catch_keyword)] @keyword
(statement_label) @label
; Comments
2022-08-17 05:40:21 +04:00
(comment) @comment
(multiline_comment) @comment
2022-04-08 22:10:37 +04:00
; String literals
(line_str_text) @string
(str_escaped_char) @string
(multi_line_str_text) @string
(raw_str_part) @string
(raw_str_end_part) @string
2022-08-17 05:40:21 +04:00
(raw_str_interpolation_start) @punctuation.special
2022-04-08 22:10:37 +04:00
["\"" "\"\"\""] @string
; Lambda literals
2022-08-17 05:40:21 +04:00
(lambda_literal "in" @keyword.operator)
2022-04-08 22:10:37 +04:00
; Basic literals
[
2022-08-17 05:40:21 +04:00
(hex_literal)
(oct_literal)
(bin_literal)
2022-04-08 22:10:37 +04:00
] @constant.numeric
2022-08-17 05:40:21 +04:00
(integer_literal) @constant.numeric.integer
2022-04-08 22:10:37 +04:00
(real_literal) @constant.numeric.float
(boolean_literal) @constant.builtin.boolean
"nil" @variable.builtin
2022-08-17 05:40:21 +04:00
"?" @type
(type_annotation "!" @type)
(simple_identifier) @variable
2022-04-08 22:10:37 +04:00
; Operators
[
2022-08-17 05:40:21 +04:00
"!"
"?"
2022-08-17 05:40:21 +04:00
"+"
"-"
"*"
"/"
"%"
"="
"+="
"-="
"*="
"/="
"<"
">"
"<="
">="
"++"
"--"
"&"
"~"
"%="
"!="
"!=="
"=="
"==="
"??"
"->"
"..<"
"..."
(custom_operator)
2022-04-08 22:10:37 +04:00
] @operator
(value_parameter_pack ["each" @keyword])
(value_pack_expansion ["repeat" @keyword])
(type_parameter_pack ["each" @keyword])
(type_pack_expansion ["repeat" @keyword])