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

172 lines
3.6 KiB
Scheme
Raw Normal View History

2022-08-17 05:40:21 +04:00
; Upstream: https://github.com/alex-pinkus/tree-sitter-swift/blob/8d2fd80e3322df51e3f70952e60d57f5d4077eb8/queries/highlights.scm
(line_string_literal
["\\(" ")"] @punctuation.special)
["." ";" ":" "," ] @punctuation.delimiter
["(" ")" "[" "]" "{" "}"] @punctuation.bracket ; TODO: "\\(" ")" in interpolations should be @punctuation.special
2022-04-08 22:10:37 +04:00
; Identifiers
(attribute) @variable
(type_identifier) @type
(self_expression) @variable.builtin
; Declarations
"func" @keyword.function
[
(visibility_modifier)
(member_modifier)
(function_modifier)
(property_modifier)
(parameter_modifier)
(inheritance_modifier)
] @keyword
(function_declaration (simple_identifier) @function.method)
2022-08-17 05:40:21 +04:00
(function_declaration "init" @constructor)
2022-04-08 22:10:37 +04:00
(throws) @keyword
"async" @keyword
(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"
2022-04-08 22:10:37 +04:00
"some"
] @keyword
[
(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]"))
(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
"try"
"try?"
"try!"
"!"
"+"
"-"
"*"
"/"
"%"
"="
"+="
"-="
"*="
"/="
"<"
">"
"<="
">="
"++"
"--"
"&"
"~"
"%="
"!="
"!=="
"=="
"==="
"??"
"->"
"..<"
"..."
(custom_operator)
2022-04-08 22:10:37 +04:00
] @operator