nvim-treesitter/queries/kotlin/highlights.scm

171 lines
5.5 KiB
Scheme
Raw Normal View History

;;; Kotlin
2020-11-30 22:58:52 +01:00
;; Strings
2020-11-30 22:58:52 +01:00
(line_string_literal) @string
(multi_line_string_literal) @string
; Interpolated
(interpolated_identifier) @none
(interpolated_expression) @none
2020-11-30 22:58:52 +01:00
2020-12-05 21:20:56 +01:00
;; Suffixes
;; Issues:
;; - `doors` in `c = car.doors` not reconized
(navigation_expression (navigation_suffix) @property ) ; TODO to method and resetable italics
(assignment (navigation_expression (navigation_suffix) @none ))
(call_expression (navigation_expression (navigation_suffix) @none ))
(navigation_expression (navigation_expression (navigation_suffix) @none ))
(parenthesized_expression (navigation_expression (navigation_suffix) @property))
2020-11-30 22:58:52 +01:00
;; Constants
; Assume all-caps names are constants
((simple_identifier) @constant
(#vim-match? @constant "^[A-Z][A-Z_]+"))
;; Variables/fields
2020-12-05 21:20:56 +01:00
; attribute in data classes etc.
2020-12-05 22:14:20 +01:00
(class_parameter (simple_identifier) @field)
2020-12-05 21:20:56 +01:00
; variable in normal classes
(property_declaration (variable_declaration (simple_identifier) @variable))
; accessed field in blocks. `logger` in `logger.info("")`
2020-12-05 21:20:56 +01:00
(statements (call_expression (navigation_expression (simple_identifier) @variable)))
(indexing_expression (call_expression (navigation_expression (simple_identifier) @variable)))
; `classProp` in `classProp.lastIndex`
(statements (navigation_expression (simple_identifier) @variable))
; `variable` in `variable = car.doors`
2020-12-05 21:20:56 +01:00
(directly_assignable_expression (simple_identifier) @variable)
2020-11-30 22:58:52 +01:00
2020-12-05 21:20:56 +01:00
(lambda_parameters) @parameter
2020-11-30 22:58:52 +01:00
;; Builtin functions
((simple_identifier) @function.macro
2020-12-05 21:20:56 +01:00
(#vim-match? @function.macro "(^commonPrefixWith$|^commonSuffixWith$|^endsWith$|^findAnyOf$|^findLastAnyOf$|^hasSurrogatePairAt$|^ifBlank$|^ifEmpty$|^indexOf$|^indexOfAny$|^isEmpty$|^isNotBlank$|^isNotEmpty$|^isNullOrBlank$|^isNullOrEmpty$|^lastIndexOf$|^lastIndexOfAny$|^lineSequence$|^lines$|^orEmpty$|^padEnd$|^padStart$|^removePrefix$|^removeRange$|^removeSuffix$|^removeSurrounding$|^replace$|^replaceAfter$|^replaceAfterLast$|^replaceBefore$|^replaceBeforeLast$|^replaceFirst$|^replaceRange$|^split$|^splitToSequence$|^startsWith$|^subSequence$|^substring$|^substringAfter$|^substringAfterLast$|^substringBefore$|^substringBeforeLast$|^trim$|^trimEnd$|^trimStart$|^containsKey$|^containsValue$|^filter$|^filterKeys$|^filterNot$|^filterNotTo$|^filterTo$|^filterValues$|^getOrElse$|^getOrPut$|^getValue$|^ifEmpty$|^isNotEmpty$|^isNullOrEmpty$|^mapKeys$|^mapKeysTo$|^mapValues$|^mapValuesTo$|^orEmpty$|^putAll$|^remove$|^toMap$|^toMutableMap$|^toPair$|^also$|^apply$|^let$|^run$|^takeIf$|^takeUnless$|^prependIndent$|^replaceIndent$|^replaceIndentByMargin$|^trimIndent$|^trimMargin$|^all$|^any$|^asIterable$|^asSequence$|^associate$|^associateBy$|^associateByTo$|^associateTo$|^associateWith$|^associateWithTo$|^chunked$|^chunkedSequence$|^count$|^drop$|^dropLast$|^dropLastWhile$|^dropWhile$|^elementAtOrElse$|^elementAtOrNull$|^filter$|^filterIndexed$|^filterIndexedTo$|^filterNot$|^filterNotTo$|^filterTo$|^find$|^findLast$|^first$|^firstOrNull$|^flatMap$|^flatMapIndexed$|^flatMapIndexedTo$|^flatMapTo$|^fold$|^foldIndexed$|^foldRight$|^foldRightIndexed$|^forEach$|^forEachIndexed$|^getOrElse$|^getOrNull$|^groupBy$|^groupByTo$|^groupingBy$|^indexOfFirst$|^indexOfLast$|^last$|^lastOrNull$|^map$|^mapIndexed$|^mapIndexedNotNull$|^mapIndexedNotNullTo$|^mapIndexedTo$|^mapNotNull$|^mapNotNullTo$|^mapTo$|^max$|^maxBy$|^maxByOrNull$|^maxOf$|^maxOfOrNull$|^maxOfWith$|^maxOfWithOrNull$|^maxOrNull$|^maxWith$|^maxWithOrNull$|^min$|^minBy$|^minByOrNull$|^minOf$|^minOfOrNull$|^minOfWith$|^minOfWithOrNull$|^minOrNull$|^minWith$|^minWithOrNull$|^none$|^onEach$|^onEachIndexed$|^partition$|^random$|^randomOrNull$|^reduce$|^reduceIndexed$|^reduceIndexedOrNull$|^reduceOrNull$|^reduceRight$|^reduceRightIndexed$|^reduceRightIndexedOrNull$|^reduceRightOrNull$|^reversed$|^runningFold$|^runningFoldIndexed$|^runningReduce$|^runningReduceIndexed$|^scan$|^scanIndexed$|^scanReduce$|^scanReduceIndexed$|^single$|^singleOrNull$|^slice$|^sumBy$|^sumByDouble$|^sumOf$|^take$|^takeLast$|^takeLastWhile$|^takeWhile$|^toCollection$|^toHashSet$|^toList$|^toMutableList$|^toSet$|^windowed$|^windowedSequence$|^withIndex$|^zip$|^zipWithNext$)"))
2020-11-30 22:58:52 +01:00
((simple_identifier) @function.builtin
2020-12-05 21:20:56 +01:00
(#vim-match? @function.builtin "(^print$|^println$|^buildMap$|^emptyMap$|^hashMapOf$|^linkedMapOf$|^mapOf$|^mutableMapOf$|^buildSet$|^emptySet$|^hashSetOf$|^linkedSetOf$|^mutableSetOf$|^setOf$|^setOfNotNull$|^TODO$|^repeat$|^run$|^with$)"))
2020-11-30 22:58:52 +01:00
;; Numbers
2020-11-30 22:58:52 +01:00
(integer_literal) @number
;; Booleans
2020-11-30 22:58:52 +01:00
(boolean_literal) @boolean
;; Annotations
2020-12-05 22:14:20 +01:00
(annotation (single_annotation) @attribute)
;; Types
; TODO more type definitions
(variable_declaration (user_type (type_identifier) @type))
(callable_reference (type_identifier) @type)
2020-11-30 22:58:52 +01:00
;; it
(indexing_expression (simple_identifier) @variable.builtin
(#vim-match? @variable.builtin "^it$"))
2020-12-05 21:20:56 +01:00
;; Operators
[
"="
"-"
"->"
"+"
"++"
"--"
"*"
] @operator
2020-12-05 21:20:56 +01:00
;; Keyword operators
[
"in"
] @keyword.operator
2020-11-30 22:58:52 +01:00
2020-12-05 21:20:56 +01:00
((simple_identifier) @keyword.operator
(#vim-match? @keyword.operator "^to$"))
2020-11-30 22:58:52 +01:00
2020-12-05 21:20:56 +01:00
;; Keywords
2020-11-30 22:58:52 +01:00
[
"enum"
"as"
"class"
"object"
"data"
"val"
"init"
"private"
"var"
"break"
"by"
"fun"
"companion"
"return"
"constructor"
"throw"
2020-11-30 22:58:52 +01:00
] @keyword
; const does not work
;; Conditionals
[
"if"
"is"
"else"
"when"
] @conditional
;; Loops
[
"for"
"while"
] @repeat
2020-11-30 22:58:52 +01:00
;; Includes
"import" @include
"package" @include
;; Punctuation
[
"::"
2020-11-30 22:58:52 +01:00
";"
"."
","
] @punctuation.delimiter
[
"$"
"${"
"}"
] @none
2020-11-30 22:58:52 +01:00
[
"["
"]"
"{"
"}"
"("
")"
] @punctuation.bracket
2020-11-30 23:06:01 +01:00
[
"$"
] @punctuation.special
2020-11-30 22:58:52 +01:00
;; Comments
(comment) @comment
2020-12-05 21:20:56 +01:00
; Functions
2020-11-30 22:58:52 +01:00
(function_declaration (simple_identifier) @function)
; TODO parameter
2020-11-30 22:58:52 +01:00
(ERROR) @error