nvim-treesitter/queries/swift/highlights.scm

311 lines
4.3 KiB
Scheme
Raw Normal View History

2024-01-06 15:05:50 +09:00
[
"."
";"
":"
","
] @punctuation.delimiter
2022-10-28 17:20:26 +03:00
; TODO: "\\(" ")" in interpolations should be @punctuation.special
2024-01-06 15:05:50 +09:00
[
"\\("
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket
2022-01-16 11:04:18 +01:00
; Identifiers
(attribute) @variable
2024-01-06 15:05:50 +09:00
2022-01-16 11:04:18 +01:00
(type_identifier) @type
2024-01-06 15:05:50 +09:00
2022-01-16 11:04:18 +01:00
(self_expression) @variable.builtin
; Declarations
"func" @keyword.function
2022-10-28 17:20:26 +03:00
2022-01-16 11:04:18 +01:00
[
(visibility_modifier)
(member_modifier)
(function_modifier)
(property_modifier)
(parameter_modifier)
(inheritance_modifier)
2023-08-12 12:14:53 +02:00
(mutation_modifier)
] @keyword.modifier
2022-01-16 11:04:18 +01:00
2024-01-06 15:05:50 +09:00
(function_declaration
(simple_identifier) @function.method)
2024-03-24 01:10:18 +01:00
(init_declaration
2024-01-06 15:05:50 +09:00
"init" @constructor)
2022-01-16 11:04:18 +01:00
(throws) @keyword
2024-01-06 15:05:50 +09:00
2022-01-16 11:04:18 +01:00
(where_keyword) @keyword
2024-01-06 15:05:50 +09:00
(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))
(pattern
bound_identifier: (simple_identifier)) @variable
2022-01-16 11:04:18 +01:00
[
"protocol"
"extension"
"indirect"
"nonisolated"
"override"
"convenience"
"required"
"some"
2024-03-24 01:10:18 +01:00
"any"
"weak"
"unowned"
"didSet"
"willSet"
] @keyword
2022-01-16 11:04:18 +01:00
2024-04-23 12:23:15 -07:00
[
"enum"
"struct"
"class"
"typealias"
] @keyword.type
[
"async"
"await"
] @keyword.coroutine
[
(getter_specifier)
(setter_specifier)
(modify_specifier)
] @keyword
2024-06-10 10:05:10 -07:00
(shebang_line) @keyword.directive
2024-01-06 15:05:50 +09:00
(class_body
(property_declaration
(pattern
(simple_identifier) @variable.member)))
2024-01-06 15:05:50 +09:00
(protocol_property_declaration
(pattern
(simple_identifier) @variable.member))
2024-01-06 15:05:50 +09:00
2023-08-12 12:14:53 +02:00
(navigation_expression
2024-01-06 15:05:50 +09:00
(navigation_suffix
(simple_identifier) @variable.member))
2024-01-06 15:05:50 +09:00
2023-08-12 12:14:53 +02:00
(value_argument
name: (value_argument_label) @variable.member)
2022-01-16 11:04:18 +01:00
2024-01-06 15:05:50 +09:00
(import_declaration
"import" @keyword.import)
2022-01-16 11:04:18 +01:00
2024-01-06 15:05:50 +09:00
(enum_entry
"case" @keyword)
2022-01-16 11:04:18 +01:00
2024-03-24 01:10:18 +01:00
; Attributes
(modifiers
(attribute) @attribute.builtin)
(modifiers
(attribute
(user_type
(type_identifier) @attribute.builtin)))
2022-01-16 11:04:18 +01:00
; Function calls
2024-01-06 15:05:50 +09:00
(call_expression
(simple_identifier) @function.call) ; foo()
(call_expression
; foo.bar.baz(): highlight the baz()
2022-01-16 11:04:18 +01:00
(navigation_expression
2024-01-06 15:05:50 +09:00
(navigation_suffix
(simple_identifier) @function.call)))
2023-08-12 12:14:53 +02:00
(call_expression
2024-01-06 15:05:50 +09:00
(prefix_expression
(simple_identifier) @function.call)) ; .foo()
2022-01-16 11:04:18 +01:00
((navigation_expression
2024-01-06 15:05:50 +09:00
(simple_identifier) @type) ; SomeType.method(): highlight SomeType as a type
(#lua-match? @type "^[A-Z]"))
2022-01-16 11:04:18 +01:00
(directive) @function.macro
2024-01-06 15:05:50 +09:00
2022-01-16 11:04:18 +01:00
(diagnostic) @function.macro
; Statements
2024-01-06 15:05:50 +09:00
(for_statement
"for" @keyword.repeat)
(for_statement
"in" @keyword.repeat)
(for_statement
(pattern) @variable)
2022-01-16 11:04:18 +01:00
(else) @keyword
2024-01-06 15:05:50 +09:00
2022-01-16 11:04:18 +01:00
(as_operator) @keyword
2024-01-06 15:05:50 +09:00
[
"while"
"repeat"
"continue"
"break"
] @keyword.repeat
[
"let"
"var"
] @keyword
(guard_statement
"guard" @keyword.conditional)
(if_statement
"if" @keyword.conditional)
2022-01-16 11:04:18 +01:00
2024-01-06 15:05:50 +09:00
(switch_statement
"switch" @keyword.conditional)
(switch_entry
"case" @keyword)
(switch_entry
"fallthrough" @keyword)
(switch_entry
(default_keyword) @keyword)
2022-01-16 11:04:18 +01:00
"return" @keyword.return
2024-01-06 15:05:50 +09:00
(ternary_expression
2024-01-06 15:05:50 +09:00
[
"?"
":"
] @keyword.conditional)
2022-01-16 11:04:18 +01:00
2024-01-06 15:05:50 +09:00
[
"do"
(throw_keyword)
(catch_keyword)
] @keyword
2022-01-16 11:04:18 +01:00
(statement_label) @label
; Comments
2022-09-26 10:19:02 +01:00
[
2024-01-06 15:05:50 +09:00
(comment)
(multiline_comment)
2022-09-26 10:19:02 +01:00
] @comment @spell
2022-01-16 11:04:18 +01:00
((comment) @comment.documentation
(#lua-match? @comment.documentation "^///[^/]"))
((comment) @comment.documentation
(#lua-match? @comment.documentation "^///$"))
((multiline_comment) @comment.documentation
(#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$"))
2022-01-16 11:04:18 +01:00
; String literals
(line_str_text) @string
2024-01-06 15:05:50 +09:00
2022-01-16 11:04:18 +01:00
(str_escaped_char) @string
2024-01-06 15:05:50 +09:00
2022-01-16 11:04:18 +01:00
(multi_line_str_text) @string
2024-01-06 15:05:50 +09:00
2022-01-16 11:04:18 +01:00
(raw_str_part) @string
2024-01-06 15:05:50 +09:00
2022-01-16 11:04:18 +01:00
(raw_str_end_part) @string
2024-01-06 15:05:50 +09:00
2022-01-16 11:04:18 +01:00
(raw_str_interpolation_start) @punctuation.special
2024-01-06 15:05:50 +09:00
[
"\""
"\"\"\""
] @string
2022-01-16 11:04:18 +01:00
; Lambda literals
2024-01-06 15:05:50 +09:00
(lambda_literal
"in" @keyword.operator)
2022-01-16 11:04:18 +01:00
; Basic literals
[
2024-01-06 15:05:50 +09:00
(integer_literal)
(hex_literal)
(oct_literal)
(bin_literal)
2022-01-16 11:04:18 +01:00
] @number
2024-01-06 15:05:50 +09:00
feat!: align standard captures with upstream Problem: Sharing highlight queries with upstream tree-sitter and Helix is difficult. Solution: Where reasonable, use capture names in tree-sitter's standard list or Helix's Atom-style hierarchy. Specifically: * tree-sitter "standard capture names" (https://github.com/tree-sitter/tree-sitter/blob/3f44b896852eb7daaa6df4fb778c9bb52c70c815/highlight/src/lib.rs#L20-L72): - `@parameter` -> `@variable.parameter` - `@field` -> `@variable.member` - `@namespace` -> `@module` - `@float` -> `@number.float` - `@symbol` -> `@string.special.symbol` - `@string.regex` -> `@string.regexp` - `@text.*` -> `@markup.*` (`strong`, `italic`, `link`, `strikethrough`; with exceptions; see below) - `@text.title` -> `@markup.heading` - `@text.literal` -> `@markup.raw` - `@text.reference` -> `@markup.link` - `@text.uri` -> `@markup.link.url` (in markup links) - `@string.special` -> `@markup.link.label` (non-url links) - `@punctuation.special` -> `@markup.list` (markdown lists only; move subitems from `@text.todo`) * Helix captures (https://docs.helix-editor.com/master/themes.html#syntax-highlighting): - `@method` -> `@function.method` - `@method.call` -> `@function.method.call` - `@text.{todo,warning,note,danger}` -> `@comment.{error,warning,hint,info,todo}` - `@text.diff.{add,delete,}` -> `@diff.{plus,minus,delta}` - `@text.uri` -> `@string.special.url` (outside markup) - `@preproc` -> `@keyword.directive` - `@define` -> `@keyword.directive`(`.define`?) - `@storageclass` -> `@keyword.storage` - `@conditional` -> `@keyword.conditional` - `@debug` -> `@keyword.debug` - `@exception` -> `@keyword.exception` - `@include` -> `@keyword.import` - `@repeat` -> `@keyword.repeat` * cleanup - remove some redundant `@conceal` (but still allow it for conceal-only patterns) - remove obsolete `@error` (syntax linting is out of scope for this repo) - sort, cleanup capture list in `CONTRIBUTING.md`
2023-12-24 10:00:20 +01:00
(real_literal) @number.float
2024-01-06 15:05:50 +09:00
2022-01-16 11:04:18 +01:00
(boolean_literal) @boolean
2024-01-06 15:05:50 +09:00
2022-10-28 17:20:26 +03:00
"nil" @constant.builtin
2022-01-16 11:04:18 +01:00
; Regex literals
feat!: align standard captures with upstream Problem: Sharing highlight queries with upstream tree-sitter and Helix is difficult. Solution: Where reasonable, use capture names in tree-sitter's standard list or Helix's Atom-style hierarchy. Specifically: * tree-sitter "standard capture names" (https://github.com/tree-sitter/tree-sitter/blob/3f44b896852eb7daaa6df4fb778c9bb52c70c815/highlight/src/lib.rs#L20-L72): - `@parameter` -> `@variable.parameter` - `@field` -> `@variable.member` - `@namespace` -> `@module` - `@float` -> `@number.float` - `@symbol` -> `@string.special.symbol` - `@string.regex` -> `@string.regexp` - `@text.*` -> `@markup.*` (`strong`, `italic`, `link`, `strikethrough`; with exceptions; see below) - `@text.title` -> `@markup.heading` - `@text.literal` -> `@markup.raw` - `@text.reference` -> `@markup.link` - `@text.uri` -> `@markup.link.url` (in markup links) - `@string.special` -> `@markup.link.label` (non-url links) - `@punctuation.special` -> `@markup.list` (markdown lists only; move subitems from `@text.todo`) * Helix captures (https://docs.helix-editor.com/master/themes.html#syntax-highlighting): - `@method` -> `@function.method` - `@method.call` -> `@function.method.call` - `@text.{todo,warning,note,danger}` -> `@comment.{error,warning,hint,info,todo}` - `@text.diff.{add,delete,}` -> `@diff.{plus,minus,delta}` - `@text.uri` -> `@string.special.url` (outside markup) - `@preproc` -> `@keyword.directive` - `@define` -> `@keyword.directive`(`.define`?) - `@storageclass` -> `@keyword.storage` - `@conditional` -> `@keyword.conditional` - `@debug` -> `@keyword.debug` - `@exception` -> `@keyword.exception` - `@include` -> `@keyword.import` - `@repeat` -> `@keyword.repeat` * cleanup - remove some redundant `@conceal` (but still allow it for conceal-only patterns) - remove obsolete `@error` (syntax linting is out of scope for this repo) - sort, cleanup capture list in `CONTRIBUTING.md`
2023-12-24 10:00:20 +01:00
(regex_literal) @string.regexp
2022-01-16 11:04:18 +01:00
; Operators
(custom_operator) @operator
2024-01-06 15:05:50 +09:00
2022-01-16 11:04:18 +01:00
[
2024-01-06 15:05:50 +09:00
"try"
"try?"
"try!"
"+"
"-"
"*"
"/"
"%"
"="
"+="
"-="
"*="
"/="
"<"
">"
"<="
">="
"++"
"--"
"&"
2024-03-24 01:10:18 +01:00
"&&"
"|"
"||"
2024-01-06 15:05:50 +09:00
"~"
"%="
"!="
"!=="
"=="
"==="
"??"
"->"
"..<"
"..."
2023-08-12 12:14:53 +02:00
(bang)
2022-01-16 11:04:18 +01:00
] @operator