aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--lua/nvim-treesitter/parsers.lua1
-rw-r--r--queries/kotlin/highlights.scm108
3 files changed, 73 insertions, 37 deletions
diff --git a/README.md b/README.md
index 8e9fb28db..03466ba02 100644
--- a/README.md
+++ b/README.md
@@ -150,6 +150,7 @@ We are looking for maintainers to add more parsers and to write query files for
- [x] [jsdoc](https://github.com/tree-sitter/tree-sitter-jsdoc) (maintained by @steelsojka)
- [x] [json](https://github.com/tree-sitter/tree-sitter-json) (maintained by @steelsojka)
- [ ] [julia](https://github.com/tree-sitter/tree-sitter-julia)
+- [x] [kotlin](https://github.com/QthCN/tree-sitter-kotlin) (maintained by @tormodatt)
- [x] [lua](https://github.com/nvim-treesitter/tree-sitter-lua) (maintained by @vigoux)
- [x] [nix](https://github.com/cstrahan/tree-sitter-nix) (maintained by @leo60228)
- [x] [ocaml](https://github.com/tree-sitter/tree-sitter-ocaml) (maintained by @undu)
diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua
index 602b9b740..5fe0d0cb7 100644
--- a/lua/nvim-treesitter/parsers.lua
+++ b/lua/nvim-treesitter/parsers.lua
@@ -116,6 +116,7 @@ list.kotlin = {
url = "https://github.com/QthCN/tree-sitter-kotlin",
files = { "src/parser.c" },
},
+ maintainers = {"@tormodatt"},
}
list.html = {
diff --git a/queries/kotlin/highlights.scm b/queries/kotlin/highlights.scm
index 60ab279ac..e896b74a3 100644
--- a/queries/kotlin/highlights.scm
+++ b/queries/kotlin/highlights.scm
@@ -1,18 +1,19 @@
-;;; Kotlin
+;;; Kotlin
;; Issues
; mapOf with type definition AND multiple entries are not highligted correctly. Issue in parser. Eg.
; a = mapOf<String, String>(AA.value to AA.value, AA.value to AA.value)
+;; parser does not recognice `in` and `downto` in `for (i in 5..1) print(i)`
-(function_modifier) @type
-
-;; String
+;; Strings
(line_string_literal) @string
(multi_line_string_literal) @string
-(line_string_literal (interpolated_identifier)) @string
-(line_string_literal (interpolated_expression (line_string_literal))) @string
+; Interpolated
+(interpolated_identifier) @none
+(interpolated_expression) @none
+
;; Constants
; Assume all-caps names are constants
@@ -20,17 +21,24 @@
(#vim-match? @constant "^[A-Z][A-Z_]+"))
-;; Variables
-(class_parameter (simple_identifier) @variable.builtin)
+;; Variables/fields
+; field in data classes etc.
+(class_parameter (simple_identifier) @field)
+; field in normal classes
+(property_declaration (variable_declaration (simple_identifier) @field))
+; accessed field in blocks. `logger` in `logger.info("")`
+(statements (call_expression (navigation_expression (simple_identifier) @field)))
-; Class level
-(property_declaration (variable_declaration (simple_identifier) @variable.builtin))
+(statements (navigation_expression (simple_identifier) @field))
-(statements (call_expression (navigation_expression (simple_identifier) @variable.builtin)))
+(call_expression (navigation_expression (simple_identifier) @field))
-(directly_assignable_expression (navigation_expression (simple_identifier) @variable.builtin))
+; TODO check if this is needed
+(directly_assignable_expression (navigation_expression (simple_identifier) @string))
+; `variable` in `variable = car.doors`
+(directly_assignable_expression (simple_identifier) @field)
-(directly_assignable_expression (simple_identifier) @variable.builtin)
+(lambda_parameters) @field
; TODO not supported yet
@@ -41,44 +49,55 @@
;; Property access syntax
-; TODO
-; a = get().value etc
-(assignment (navigation_expression (navigation_suffix) @type ))
-; val a = A.get().value etc
-(property_declaration (navigation_expression (navigation_suffix) @type ))
-; value in `mapOf(A.value to B.value)` etc.
-(infix_expression (navigation_expression (navigation_suffix) @type ))
+; `value` in `a = get().value`
+(assignment (navigation_expression (navigation_suffix) @property ))
+; `value` in `val a = A.get().value`
+(property_declaration (navigation_expression (navigation_suffix) @property ))
+; `value` in `mapOf(A.value to B.value)`
+(infix_expression (navigation_expression (navigation_suffix) @property ))
; java in `Car::class.java`
-(value_argument (navigation_expression (navigation_suffix) @type ))
-
-
-;; Interpolated
-
-(interpolated_identifier) @type
-(interpolated_expression) @type
+(value_argument (navigation_expression (navigation_suffix) @method ))
;; Builtin functions
-((simple_identifier) @function.builtin
- (#vim-match? @function.builtin "(^let$|^listOf$|^mapOf$|^map$)"))
-
+;; TODO add more functions
+((simple_identifier) @function.macro
+ (#vim-match? @function.macro "(^let$|^listOf$|^mapOf$|^map$|^downto$)"))
+;; TODO add more functions
((simple_identifier) @function.builtin
- (#vim-match? @function.builtin "^to$"))
+ (#vim-match? @function.builtin "(^print$|^println$)"))
-(modifiers (annotation (user_type (type_identifier)))) @attribute
+((simple_identifier) @keyword.operator
+ (#vim-match? @keyword.operator "^to$"))
-(annotation) @attribute
+;; Numbers
(integer_literal) @number
+;; Booleans
(boolean_literal) @boolean
+;; Annotations
+(annotation (single_annotation) @annotation)
+
+;; Types
+; TODO more type definitions
+(variable_declaration (user_type (type_identifier) @type))
+(callable_reference (type_identifier) @type)
+
;; it
-(indexing_expression (simple_identifier) @type
- (#vim-match? @type "^it$"))
+(indexing_expression (simple_identifier) @variable.builtin
+ (#vim-match? @variable.builtin "^it$"))
+
+
+;; Keyword operators
+
+[
+"in"
+] @keyword.operator
;; Keywords
@@ -99,6 +118,7 @@
"companion"
"return"
"constructor"
+ "throw"
] @keyword
; const does not work
@@ -112,6 +132,13 @@
] @conditional
+;; Loops
+[
+"for"
+"while"
+] @repeat
+
+
;; Includes
"import" @include
@@ -121,12 +148,19 @@
;; Punctuation
[
+"::"
";"
"."
","
] @punctuation.delimiter
[
+"$"
+"${"
+"}"
+] @none
+
+[
"["
"]"
"{"
@@ -137,8 +171,6 @@
[
"$"
-"${"
-"}"
] @punctuation.special
;; Comments
@@ -159,4 +191,6 @@
"*"
] @operator
+; TODO parameter
+
(ERROR) @error