Unnamed repository; edit this file 'description' to name the repository.
Add Koto language support (#12307)
Ian Hobson 2024-12-20
parent eaff0c3 · commit 06d0f33
-rw-r--r--book/src/generated/lang-support.md1
-rw-r--r--languages.toml15
-rw-r--r--runtime/queries/koto/folds.scm9
-rw-r--r--runtime/queries/koto/highlights.scm152
-rw-r--r--runtime/queries/koto/indents.scm61
-rw-r--r--runtime/queries/koto/injections.scm2
-rw-r--r--runtime/queries/koto/locals.scm30
-rw-r--r--runtime/queries/koto/textobjects.scm38
8 files changed, 308 insertions, 0 deletions
diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md
index 0c3bf78e..dc4a5c8b 100644
--- a/book/src/generated/lang-support.md
+++ b/book/src/generated/lang-support.md
@@ -115,6 +115,7 @@
| kdl | ✓ | ✓ | ✓ | |
| koka | ✓ | | ✓ | `koka` |
| kotlin | ✓ | | | `kotlin-language-server` |
+| koto | ✓ | ✓ | ✓ | `koto-ls` |
| latex | ✓ | ✓ | | `texlab` |
| ld | ✓ | | ✓ | |
| ldif | ✓ | | | |
diff --git a/languages.toml b/languages.toml
index d5235914..9adb1865 100644
--- a/languages.toml
+++ b/languages.toml
@@ -53,6 +53,7 @@ jq-lsp = { command = "jq-lsp" }
jsonnet-language-server = { command = "jsonnet-language-server", args= ["-t", "--lint"] }
julia = { command = "julia", timeout = 60, args = [ "--startup-file=no", "--history-file=no", "--quiet", "-e", "using LanguageServer; runserver()", ] }
koka = { command = "koka", args = ["--language-server", "--lsstdio"] }
+koto-ls = { command = "koto-ls" }
kotlin-language-server = { command = "kotlin-language-server" }
lean = { command = "lean", args = [ "--server", "--memory=1024" ] }
ltex-ls = { command = "ltex-ls" }
@@ -3966,6 +3967,20 @@ name = "amber"
source = { git = "https://github.com/amber-lang/tree-sitter-amber", rev = "c6df3ec2ec243ed76550c525e7ac3d9a10c6c814" }
[[language]]
+name = "koto"
+scope = "source.koto"
+injection-regex = "koto"
+file-types = ["koto"]
+comment-token = "#"
+block-comment-tokens = ["#-", "-#"]
+indent = { tab-width = 2, unit = " " }
+language-servers = ["koto-ls"]
+
+[[grammar]]
+name = "koto"
+source = { git = "https://github.com/koto-lang/tree-sitter-koto", rev = "b420f7922d0d74905fd0d771e5b83be9ee8a8a9a" }
+
+[[language]]
name = "gpr"
scope = "source.gpr"
injection-regex = "gpr"
diff --git a/runtime/queries/koto/folds.scm b/runtime/queries/koto/folds.scm
new file mode 100644
index 00000000..d20d0120
--- /dev/null
+++ b/runtime/queries/koto/folds.scm
@@ -0,0 +1,9 @@
+[
+ (assign)
+ (comment)
+ (function)
+ (list)
+ (map)
+ (tuple)
+ (string)
+] @fold
diff --git a/runtime/queries/koto/highlights.scm b/runtime/queries/koto/highlights.scm
new file mode 100644
index 00000000..61f97123
--- /dev/null
+++ b/runtime/queries/koto/highlights.scm
@@ -0,0 +1,152 @@
+[
+ "="
+ "+"
+ "-"
+ "*"
+ "/"
+ "%"
+ "+="
+ "-="
+ "*="
+ "/="
+ "%="
+ "=="
+ "!="
+ "<"
+ ">"
+ "<="
+ ">="
+ ".."
+ "..="
+ "->"
+ (null_check)
+] @operator
+
+[
+ "let"
+] @keyword
+
+[
+ "and"
+ "not"
+ "or"
+] @keyword.operator
+
+[
+ "return"
+ "yield"
+] @keyword.control.return
+
+[
+ "if"
+ "then"
+ "else"
+ "else if"
+ "match"
+ "switch"
+] @keyword.control.conditional
+
+[
+ (break)
+ (continue)
+ "for"
+ "in"
+ "loop"
+ "until"
+ "while"
+] @keyword.control.repeat
+
+[
+ "throw"
+ "try"
+ "catch"
+ "finally"
+] @keyword.control.exception
+
+[
+ "export"
+ "from"
+ "import"
+ "as"
+] @keyword.control.import
+
+(string (interpolation ("{") @punctuation.special))
+(string (interpolation ("}") @punctuation.special))
+
+[
+ "("
+ ")"
+ "["
+ "]"
+ "{"
+ "}"
+ "|"
+] @punctuation.bracket
+
+[
+ ";"
+ ":"
+ ","
+] @punctuation.delimiter
+
+(import_module
+ (identifier) @module)
+
+(import_item
+ (identifier) @module)
+
+(export
+ (identifier) @module)
+
+(call
+ function: (identifier) @function.method)
+
+(chain
+ lookup: (identifier) @variable.other.member)
+
+[
+ (true)
+ (false)
+] @constant.builtin.boolean
+
+(comment) @comment
+
+(debug) @keyword
+
+(string) @string
+
+(fill_char) @punctuation.delimiter
+
+(alignment) @operator
+
+(escape) @constant.character.escape
+
+(null) @constant.builtin
+
+(number) @constant.numeric
+
+(meta) @keyword.directive
+
+(meta
+ name: (identifier) @variable.other.member)
+
+(entry_inline
+ key: (identifier) @variable.other.member)
+
+(entry_block
+ key: (identifier) @variable.other.member)
+
+(self) @variable.builtin
+
+(variable
+ type: (identifier) @type)
+
+(arg
+ (_ (identifier) @variable.parameter))
+
+(ellipsis) @variable.parameter
+
+(function
+ output_type: (identifier) @type)
+
+(identifier) @variable
diff --git a/runtime/queries/koto/indents.scm b/runtime/queries/koto/indents.scm
new file mode 100644
index 00000000..0eab2b50
--- /dev/null
+++ b/runtime/queries/koto/indents.scm
@@ -0,0 +1,61 @@
+[
+ (list)
+ (map)
+ (tuple)
+] @indent
+
+[
+ (for)
+ (else_if)
+ (else)
+ (match)
+ (switch)
+ (until)
+ (while)
+] @indent @extend
+
+(assign
+ "=" @indent @extend
+ !rhs
+)
+(assign
+ "=" @indent @extend
+ rhs: (_) @anchor
+ (#not-same-line? @indent @anchor)
+)
+
+(if
+ condition: (_) @indent @extend
+ !then
+)
+(if
+ condition: (_) @indent @extend
+ then: (_) @anchor
+ (#not-same-line? @indent @anchor)
+)
+
+(function
+ (args) @indent @extend
+ !body
+)
+(function
+ (args) @indent @extend
+ body: (_) @anchor
+ (#not-same-line? @indent @anchor)
+)
+
+(match_arm
+ "then" @indent @extend
+ !then
+)
+(match_arm
+ "then" @indent @extend
+ then: (_) @anchor
+ (#not-same-line? @indent @anchor)
+)
+
+[
+ "}"
+ "]"
+ ")"
+] @outdent
diff --git a/runtime/queries/koto/injections.scm b/runtime/queries/koto/injections.scm
new file mode 100644
index 00000000..2f0e58eb
--- /dev/null
+++ b/runtime/queries/koto/injections.scm
@@ -0,0 +1,2 @@
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/runtime/queries/koto/locals.scm b/runtime/queries/koto/locals.scm
new file mode 100644
index 00000000..1886b188
--- /dev/null
+++ b/runtime/queries/koto/locals.scm
@@ -0,0 +1,30 @@
+; Scopes
+(module (_) @local.scope)
+
+(function
+ body: (_) @local.scope)
+
+; Definitions
+(assign
+ lhs: (identifier) @local.definition)
+
+(variable
+ (identifier) @local.definition)
+
+(arg
+ (identifier) @local.definition)
+
+(arg
+ (variable (identifier)) @local.definition)
+
+(import_item
+ (identifier) @local.definition)
+
+(entry_block
+ (identifier) @local.definition)
+
+(entry_inline
+ (identifier) @local.definition)
+
+; References
+(identifier) @local.reference
diff --git a/runtime/queries/koto/textobjects.scm b/runtime/queries/koto/textobjects.scm
new file mode 100644
index 00000000..15455689
--- /dev/null
+++ b/runtime/queries/koto/textobjects.scm
@@ -0,0 +1,38 @@
+(comment) @comment.inside
+
+(comment)+ @comment.around
+
+(function
+ body: (_) @function.inside) @function.around
+
+(args
+ ((arg) @parameter.inside . ","? @parameter.around) @parameter.around)
+
+(call_args
+ ((call_arg) @parameter.inside . ","? @parameter.around) @parameter.around)
+
+(chain
+ call: (tuple
+ ((element) @parameter.inside . ","? @parameter.around) @parameter.around))
+
+(map
+ ((entry_inline) @entry.inside . ","? @entry.around) @entry.around)
+
+(map_block
+ ((entry_block) @entry.inside) @entry.around)
+
+(list
+ ((element) @entry.inside . ","? @entry.around) @entry.around)
+
+(tuple
+ (_) @entry.around)
+
+(assign
+ (meta (test))
+ (function body: (_) @test.inside)
+) @test.around
+
+(entry_block
+ key: (meta (test))
+ value: (function body: (_) @test.inside)
+) @test.around