Debian Codegraph @

runtime/queries/kotlin/highlights.scm

raw symbols SCIP
1 ;;; Identifiers
2 (simple_identifier) @variable
3
4 ; `field` keyword inside property getter/setter
5 ; FIXME: This will highlight the keyword outside of getters and setters
6 ; since tree-sitter does not allow us to check for arbitrary nestation
7 ((simple_identifier) @variable.builtin
8 (#eq? @variable.builtin "field"))
9
10 ; `it` keyword inside lambdas
11 ; FIXME: This will highlight the keyword outside of lambdas since tree-sitter
12 ; does not allow us to check for arbitrary nestation
13 ((simple_identifier) @variable.builtin
14 (#eq? @variable.builtin "it"))
15
16
17 ;;; Operators & Punctuation
18
19 [
20 "."
21 ","
22 ";"
23 ":"
24 "::"
25 ] @punctuation.delimiter
26
27 [
28 "(" ")"
29 "[" "]"
30 "{" "}"
31 ] @punctuation.bracket
32
33 [
34 "!"
35 "!="
36 "!=="
37 "="
38 "=="
39 "==="
40 ">"
41 ">="
42 "<"
43 "<="
44 "||"
45 "&&"
46 "+"
47 "++"
48 "+="
49 "-"
50 "--"
51 "-="
52 "*"
53 "*="
54 "/"
55 "/="
56 "%"
57 "%="
58 "?."
59 "?:"
60 "!!"
61 "is"
62 "in"
63 "as"
64 "as?"
65 ".."
66 "->"
67 ] @operator
68
69 ; `?` in a nullable type (`Int?`) — now its own (quest) node.
70 (nullable_type (quest) @operator)
71
72 ;;; String interpolation
73
74 (string_literal
75 (interpolation_identifier_start) @punctuation.special
76 (interpolated_identifier) @variable)
77 (string_literal
78 (interpolation_expression_start) @punctuation.special
79 (interpolated_expression) @none
80 (interpolation_expression_end) @punctuation.special)
81
82 ; `it` and `this` inside string interpolation
83 ((interpolated_identifier) @variable.builtin
84 (#eq? @variable.builtin "it"))
85 ((interpolated_identifier) @variable.builtin
86 (#eq? @variable.builtin "this"))
87
88 ;;; Keywords
89
90 (type_alias "typealias" @keyword)
91 [
92 (class_modifier)
93 (member_modifier)
94 (function_modifier)
95 (property_modifier)
96 (platform_modifier)
97 (variance_modifier)
98 (parameter_modifier)
99 (visibility_modifier)
100 (reification_modifier)
101 (inheritance_modifier)
102 ]@keyword
103
104 [
105 "val"
106 "var"
107 "enum"
108 "class"
109 "object"
110 "interface"
111 "companion"
112 ; "typeof" ; NOTE: It is reserved for future use
113 ] @keyword
114
115 ("fun") @keyword.function
116
117 (jump_expression) @keyword.control.return
118
119 [
120 "if"
121 "else"
122 "when"
123 ] @keyword.control.conditional
124
125 [
126 "for"
127 "do"
128 "while"
129 ] @keyword.control.repeat
130
131 [
132 "try"
133 "catch"
134 "throw"
135 "finally"
136 ] @keyword.control.exception
137
138 (annotation
139 "@" @attribute (use_site_target)? @attribute)
140 (annotation
141 (user_type
142 (type_identifier) @attribute))
143 (annotation
144 (constructor_invocation
145 (user_type
146 (type_identifier) @attribute)))
147
148 (file_annotation
149 "@" @attribute "file" @attribute ":" @attribute)
150 (file_annotation
151 (user_type
152 (type_identifier) @attribute))
153 (file_annotation
154 (constructor_invocation
155 (user_type
156 (type_identifier) @attribute)))
157
158 ;;; Literals
159 ; NOTE: Escapes not allowed in multi-line strings
160 (character_literal (character_escape_seq) @constant.character.escape)
161
162 (string_literal) @string
163
164 (character_literal) @constant.character
165
166 (boolean_literal) @constant.builtin.boolean
167 (null_literal) @constant.builtin
168
169 (real_literal) @constant.numeric.float
170 [
171 (integer_literal)
172 (long_literal)
173 (hex_literal)
174 (bin_literal)
175 (unsigned_literal)
176 ] @constant.numeric.integer
177
178 [
179 (line_comment)
180 (multiline_comment)
181 (shebang_line)
182 ] @comment
183
184 ;;; Constants
185
186 (enum_entry
187 (simple_identifier) @constant)
188
189 ; SCREAMING CASE identifiers are assumed to be constants
190 ((simple_identifier) @constant
191 (#match? @constant "^[A-Z][A-Z0-9_]*$"))
192
193 ;;; Navigation, Members & Function calls
194
195 ; generic property navigation (e.g. obj.property)
196 (_
197 (navigation_suffix
198 (simple_identifier) @variable.other.member))
199
200 ; generic function call (e.g. foo())
201 (call_expression
202 . (simple_identifier) @function)
203
204 ; method call via navigation (e.g. obj.method())
205 (call_expression
206 (navigation_expression
207 (navigation_suffix
208 (simple_identifier) @function) . ))
209
210 ; infix function call (e.g. 1 to 2)
211 (infix_expression
212 . (_) .
213 (simple_identifier) @function)
214
215 ; builtin function calls
216 (call_expression
217 . (simple_identifier) @function.builtin
218 (#match? @function.builtin "^(arrayOf|arrayOfNulls|byteArrayOf|shortArrayOf|intArrayOf|longArrayOf|ubyteArrayOf|ushortArrayOf|uintArrayOf|ulongArrayOf|floatArrayOf|doubleArrayOf|booleanArrayOf|charArrayOf|emptyArray|mapOf|setOf|listOf|emptyMap|emptySet|emptyList|mutableMapOf|mutableSetOf|mutableListOf|print|println|error|TODO|run|runCatching|repeat|lazy|lazyOf|enumValues|enumValueOf|assert|check|checkNotNull|require|requireNotNull|with|suspend|synchronized)$"))
219
220 ; constant access via navigation (e.g. Foo.CONSTANT)
221 (_
222 (navigation_suffix
223 (simple_identifier) @constant
224 (#match? @constant "^[A-Z][A-Z0-9_]*$")))
225
226 ; object or class reference (e.g. TextObjects.TEXT)
227 ((navigation_expression
228 . (simple_identifier) @type)
229 (#match? @type "^[A-Z]"))
230
231 ;;; Function definitions
232
233 ; lambda parameters
234 (lambda_literal
235 (lambda_parameters
236 (variable_declaration
237 (simple_identifier) @variable.parameter)))
238
239 (parameter_with_optional_type
240 (simple_identifier) @variable.parameter)
241
242 (parameter
243 (simple_identifier) @variable.parameter)
244
245 ; named arguments
246 (value_argument
247 . (simple_identifier) @variable.parameter)
248
249 (anonymous_initializer
250 ("init") @constructor)
251
252 (constructor_invocation
253 (user_type
254 (type_identifier) @constructor))
255
256 (secondary_constructor
257 ("constructor") @constructor)
258 (primary_constructor) @constructor
259
260 (getter
261 ("get") @function.builtin)
262 (setter
263 ("set") @function.builtin)
264
265 ; normal function
266 (function_declaration
267 (modifiers)?
268 (type_parameters)?
269 (simple_identifier) @function)
270
271 ; extension function
272 (function_declaration
273 receiver: (receiver_type)
274 (simple_identifier) @function)
275
276 ; TODO: Separate labeled returns/breaks/continue/super/this
277 ; Must be implemented in the parser first
278 (label) @label
279
280 (import_header
281 (identifier
282 (simple_identifier) @function @_import .)
283 (import_alias
284 (type_identifier) @function)?
285 (#match? @_import "^[a-z]"))
286
287 ; The last `simple_identifier` in a `import_header` will always either be a function
288 ; or a type. Classes can appear anywhere in the import path, unlike functions
289 (import_header
290 (identifier
291 (simple_identifier) @type @_import)
292 (import_alias
293 (type_identifier) @type)?
294 (#match? @_import "^[A-Z]"))
295
296 (import_header
297 "import" @keyword.control.import)
298
299 (package_header
300 . (identifier)) @namespace
301
302 (type_identifier) @type
303
304 ((type_identifier) @type.builtin
305 (#match? @type.builtin "^(Byte|Short|Int|Long|UByte|UShort|UInt|ULong|Float|Double|Boolean|Char|String|Array|ByteArray|ShortArray|IntArray|LongArray|UByteArray|UShortArray|UIntArray|ULongArray|FloatArray|DoubleArray|BooleanArray|CharArray|Map|Set|List|EmptyMap|EmptySet|EmptyList|MutableMap|MutableSet|MutableList)$"))
306
307 (type_parameter
308 (type_identifier) @type.parameter)
309
310 ((class_body
311 (property_declaration
312 (variable_declaration
313 (simple_identifier) @variable.other.member)))
314 (#not-match? @variable.other.member "^[A-Z][A-Z0-9_]*$"))
315
316 ; Extension property
317 (property_declaration
318 receiver: (receiver_type)
319 (variable_declaration
320 (simple_identifier) @variable.other.member))
321
322 (class_parameter
323 (simple_identifier) @variable.other.member)
324
325 ; `super` keyword inside classes
326 (super_expression) @variable.builtin
327
328 ; `this` this keyword inside classes
329 (this_expression) @variable.builtin