Skip to content

Commit f16a7fc

Browse files
the-mikedavisthomasskk
authored andcommitted
Update tree-sitter-swift (helix-editor#3461)
1 parent a6f202e commit f16a7fc

File tree

3 files changed

+79
-77
lines changed

3 files changed

+79
-77
lines changed

languages.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ language-server = { command = "sourcekit-lsp" }
12341234

12351235
[[grammar]]
12361236
name = "swift"
1237-
source = { git = "https://github.com/Dispersia/tree-sitter-swift", rev = "e75240f89bb3bfd3396155859ae364e5c58d7377" }
1237+
source = { git = "https://github.com/alex-pinkus/tree-sitter-swift", rev = "77c6312c8438f4dbaa0350cec92b3d6dd3d74a66" }
12381238

12391239
[[language]]
12401240
name = "erb"

runtime/queries/swift/highlights.scm

+73-60
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
[ "." ";" ":" "," ] @punctuation.delimiter
2-
[ "\\(" "(" ")" "[" "]" "{" "}"] @punctuation.bracket ; TODO: "\\(" ")" in interpolations should be @punctuation.special
1+
; Upstream: https://github.com/alex-pinkus/tree-sitter-swift/blob/8d2fd80e3322df51e3f70952e60d57f5d4077eb8/queries/highlights.scm
2+
3+
(line_string_literal
4+
["\\(" ")"] @punctuation.special)
5+
6+
["." ";" ":" "," ] @punctuation.delimiter
7+
["(" ")" "[" "]" "{" "}"] @punctuation.bracket ; TODO: "\\(" ")" in interpolations should be @punctuation.special
38

49
; Identifiers
510
(attribute) @variable
@@ -18,7 +23,7 @@
1823
] @keyword
1924

2025
(function_declaration (simple_identifier) @function.method)
21-
(function_declaration ["init" @constructor])
26+
(function_declaration "init" @constructor)
2227
(throws) @keyword
2328
"async" @keyword
2429
(where_keyword) @keyword
@@ -27,16 +32,21 @@
2732
(type_parameter (type_identifier) @variable.parameter)
2833
(inheritance_constraint (identifier (simple_identifier) @variable.parameter))
2934
(equality_constraint (identifier (simple_identifier) @variable.parameter))
30-
(non_binding_pattern bound_identifier: (simple_identifier)) @variable
35+
(pattern bound_identifier: (simple_identifier)) @variable
3136

3237
[
3338
"typealias"
3439
"struct"
3540
"class"
41+
"actor"
3642
"enum"
3743
"protocol"
3844
"extension"
3945
"indirect"
46+
"nonisolated"
47+
"override"
48+
"convenience"
49+
"required"
4050
"some"
4151
] @keyword
4252

@@ -46,12 +56,12 @@
4656
(modify_specifier)
4757
] @keyword
4858

49-
(class_body (property_declaration (value_binding_pattern (non_binding_pattern (simple_identifier) @variable.other.member))))
50-
(protocol_property_declaration (value_binding_pattern (non_binding_pattern (simple_identifier) @variable.other.member)))
59+
(class_body (property_declaration (pattern (simple_identifier) @variable.other.member)))
60+
(protocol_property_declaration (pattern (simple_identifier) @variable.other.member))
5161

52-
(import_declaration ["import" @keyword.control.import])
62+
(import_declaration "import" @keyword.control.import)
5363

54-
(enum_entry ["case" @keyword])
64+
(enum_entry "case" @keyword)
5565

5666
; Function calls
5767
(call_expression (simple_identifier) @function) ; foo()
@@ -66,24 +76,23 @@
6676
(diagnostic) @function.macro
6777

6878
; Statements
69-
(for_statement ["for" @keyword.control.repeat])
70-
(for_statement ["in" @keyword.control.repeat])
79+
(for_statement "for" @keyword.control.repeat)
80+
(for_statement "in" @keyword.control.repeat)
7181
(for_statement item: (simple_identifier) @variable)
7282
(else) @keyword
7383
(as_operator) @keyword
7484

7585
["while" "repeat" "continue" "break"] @keyword.control.repeat
7686

7787
["let" "var"] @keyword
78-
(non_binding_pattern (simple_identifier) @variable)
7988

80-
(guard_statement ["guard" @keyword.control.conditional])
81-
(if_statement ["if" @keyword.control.conditional])
82-
(switch_statement ["switch" @keyword.control.conditional])
83-
(switch_entry ["case" @keyword])
84-
(switch_entry ["fallthrough" @keyword])
89+
(guard_statement "guard" @keyword.control.conditional)
90+
(if_statement "if" @keyword.control.conditional)
91+
(switch_statement "switch" @keyword.control.conditional)
92+
(switch_entry "case" @keyword)
93+
(switch_entry "fallthrough" @keyword)
8594
(switch_entry (default_keyword) @keyword)
86-
"return" @keyword.control.return
95+
"return" @keyword.return
8796
(ternary_expression
8897
["?" ":"] @keyword.control.conditional)
8998

@@ -92,67 +101,71 @@
92101
(statement_label) @label
93102

94103
; Comments
95-
(comment) @comment.line
96-
(multiline_comment) @comment.block
104+
(comment) @comment
105+
(multiline_comment) @comment
97106

98107
; String literals
99108
(line_str_text) @string
100109
(str_escaped_char) @string
101110
(multi_line_str_text) @string
102111
(raw_str_part) @string
103112
(raw_str_end_part) @string
104-
(raw_str_interpolation_start) @string.special
113+
(raw_str_interpolation_start) @punctuation.special
105114
["\"" "\"\"\""] @string
106115

107116
; Lambda literals
108-
(lambda_literal ["in" @keyword.operator])
117+
(lambda_literal "in" @keyword.operator)
109118

110119
; Basic literals
111-
(integer_literal) @constant.numeric.integer
112120
[
113-
(hex_literal)
114-
(oct_literal)
115-
(bin_literal)
121+
(hex_literal)
122+
(oct_literal)
123+
(bin_literal)
116124
] @constant.numeric
125+
(integer_literal) @constant.numeric.integer
117126
(real_literal) @constant.numeric.float
118127
(boolean_literal) @constant.builtin.boolean
119128
"nil" @variable.builtin
120129

130+
"?" @type
131+
(type_annotation "!" @type)
132+
133+
(simple_identifier) @variable
134+
121135
; Operators
122-
(custom_operator) @operator
123136
[
124-
"try"
125-
"try?"
126-
"try!"
127-
"!"
128-
"+"
129-
"-"
130-
"*"
131-
"/"
132-
"%"
133-
"="
134-
"+="
135-
"-="
136-
"*="
137-
"/="
138-
"<"
139-
">"
140-
"<="
141-
">="
142-
"++"
143-
"--"
144-
"&"
145-
"~"
146-
"%="
147-
"!="
148-
"!=="
149-
"=="
150-
"==="
151-
"??"
152-
153-
"->"
154-
155-
"..<"
156-
"..."
137+
"try"
138+
"try?"
139+
"try!"
140+
"!"
141+
"+"
142+
"-"
143+
"*"
144+
"/"
145+
"%"
146+
"="
147+
"+="
148+
"-="
149+
"*="
150+
"/="
151+
"<"
152+
">"
153+
"<="
154+
">="
155+
"++"
156+
"--"
157+
"&"
158+
"~"
159+
"%="
160+
"!="
161+
"!=="
162+
"=="
163+
"==="
164+
"??"
165+
166+
"->"
167+
168+
"..<"
169+
"..."
170+
(custom_operator)
157171
] @operator
158-

runtime/queries/swift/locals.scm

+5-16
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
1-
(import_declaration (identifier) @definition.import)
2-
(function_declaration name: (simple_identifier) @definition.function)
3-
4-
; Scopes
51
[
6-
(statements)
7-
(for_statement)
8-
(while_statement)
9-
(repeat_while_statement)
10-
(do_statement)
11-
(if_statement)
12-
(guard_statement)
13-
(switch_statement)
14-
(property_declaration)
152
(function_declaration)
16-
(class_declaration)
17-
(protocol_declaration)
18-
] @scope
3+
] @local.scope
4+
5+
(parameter name: (simple_identifier) @local.definition)
6+
7+
(simple_identifier) @local.reference

0 commit comments

Comments
 (0)