Skip to content

Commit 2562e07

Browse files
irhrongyi
authored andcommitted
Add Koto language support (helix-editor#12307)
1 parent 4a5140f commit 2562e07

File tree

8 files changed

+308
-0
lines changed

8 files changed

+308
-0
lines changed

book/src/generated/lang-support.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
| kdl |||| |
116116
| koka || || `koka` |
117117
| kotlin || | | `kotlin-language-server` |
118+
| koto |||| `koto-ls` |
118119
| latex ||| | `texlab` |
119120
| ld || || |
120121
| ldif || | | |

languages.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ jq-lsp = { command = "jq-lsp" }
5353
jsonnet-language-server = { command = "jsonnet-language-server", args= ["-t", "--lint"] }
5454
julia = { command = "julia", timeout = 60, args = [ "--startup-file=no", "--history-file=no", "--quiet", "-e", "using LanguageServer; runserver()", ] }
5555
koka = { command = "koka", args = ["--language-server", "--lsstdio"] }
56+
koto-ls = { command = "koto-ls" }
5657
kotlin-language-server = { command = "kotlin-language-server" }
5758
lean = { command = "lean", args = [ "--server", "--memory=1024" ] }
5859
ltex-ls = { command = "ltex-ls" }
@@ -3965,6 +3966,20 @@ indent = { tab-width = 4, unit = " " }
39653966
name = "amber"
39663967
source = { git = "https://github.com/amber-lang/tree-sitter-amber", rev = "c6df3ec2ec243ed76550c525e7ac3d9a10c6c814" }
39673968

3969+
[[language]]
3970+
name = "koto"
3971+
scope = "source.koto"
3972+
injection-regex = "koto"
3973+
file-types = ["koto"]
3974+
comment-token = "#"
3975+
block-comment-tokens = ["#-", "-#"]
3976+
indent = { tab-width = 2, unit = " " }
3977+
language-servers = ["koto-ls"]
3978+
3979+
[[grammar]]
3980+
name = "koto"
3981+
source = { git = "https://github.com/koto-lang/tree-sitter-koto", rev = "b420f7922d0d74905fd0d771e5b83be9ee8a8a9a" }
3982+
39683983
[[language]]
39693984
name = "gpr"
39703985
scope = "source.gpr"

runtime/queries/koto/folds.scm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[
2+
(assign)
3+
(comment)
4+
(function)
5+
(list)
6+
(map)
7+
(tuple)
8+
(string)
9+
] @fold

runtime/queries/koto/highlights.scm

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
[
2+
"="
3+
"+"
4+
"-"
5+
"*"
6+
"/"
7+
"%"
8+
"+="
9+
"-="
10+
"*="
11+
"/="
12+
"%="
13+
"=="
14+
"!="
15+
"<"
16+
">"
17+
"<="
18+
">="
19+
".."
20+
"..="
21+
"->"
22+
(null_check)
23+
] @operator
24+
25+
[
26+
"let"
27+
] @keyword
28+
29+
[
30+
"and"
31+
"not"
32+
"or"
33+
] @keyword.operator
34+
35+
[
36+
"return"
37+
"yield"
38+
] @keyword.control.return
39+
40+
[
41+
"if"
42+
"then"
43+
"else"
44+
"else if"
45+
"match"
46+
"switch"
47+
] @keyword.control.conditional
48+
49+
[
50+
(break)
51+
(continue)
52+
"for"
53+
"in"
54+
"loop"
55+
"until"
56+
"while"
57+
] @keyword.control.repeat
58+
59+
[
60+
"throw"
61+
"try"
62+
"catch"
63+
"finally"
64+
] @keyword.control.exception
65+
66+
[
67+
"export"
68+
"from"
69+
"import"
70+
"as"
71+
] @keyword.control.import
72+
73+
(string (interpolation ("{") @punctuation.special))
74+
(string (interpolation ("}") @punctuation.special))
75+
76+
[
77+
"("
78+
")"
79+
"["
80+
"]"
81+
"{"
82+
"}"
83+
"|"
84+
] @punctuation.bracket
85+
86+
[
87+
";"
88+
":"
89+
","
90+
] @punctuation.delimiter
91+
92+
(import_module
93+
(identifier) @module)
94+
95+
(import_item
96+
(identifier) @module)
97+
98+
(export
99+
(identifier) @module)
100+
101+
(call
102+
function: (identifier) @function.method)
103+
104+
(chain
105+
lookup: (identifier) @variable.other.member)
106+
107+
[
108+
(true)
109+
(false)
110+
] @constant.builtin.boolean
111+
112+
(comment) @comment
113+
114+
(debug) @keyword
115+
116+
(string) @string
117+
118+
(fill_char) @punctuation.delimiter
119+
120+
(alignment) @operator
121+
122+
(escape) @constant.character.escape
123+
124+
(null) @constant.builtin
125+
126+
(number) @constant.numeric
127+
128+
(meta) @keyword.directive
129+
130+
(meta
131+
name: (identifier) @variable.other.member)
132+
133+
(entry_inline
134+
key: (identifier) @variable.other.member)
135+
136+
(entry_block
137+
key: (identifier) @variable.other.member)
138+
139+
(self) @variable.builtin
140+
141+
(variable
142+
type: (identifier) @type)
143+
144+
(arg
145+
(_ (identifier) @variable.parameter))
146+
147+
(ellipsis) @variable.parameter
148+
149+
(function
150+
output_type: (identifier) @type)
151+
152+
(identifier) @variable

runtime/queries/koto/indents.scm

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
[
2+
(list)
3+
(map)
4+
(tuple)
5+
] @indent
6+
7+
[
8+
(for)
9+
(else_if)
10+
(else)
11+
(match)
12+
(switch)
13+
(until)
14+
(while)
15+
] @indent @extend
16+
17+
(assign
18+
"=" @indent @extend
19+
!rhs
20+
)
21+
(assign
22+
"=" @indent @extend
23+
rhs: (_) @anchor
24+
(#not-same-line? @indent @anchor)
25+
)
26+
27+
(if
28+
condition: (_) @indent @extend
29+
!then
30+
)
31+
(if
32+
condition: (_) @indent @extend
33+
then: (_) @anchor
34+
(#not-same-line? @indent @anchor)
35+
)
36+
37+
(function
38+
(args) @indent @extend
39+
!body
40+
)
41+
(function
42+
(args) @indent @extend
43+
body: (_) @anchor
44+
(#not-same-line? @indent @anchor)
45+
)
46+
47+
(match_arm
48+
"then" @indent @extend
49+
!then
50+
)
51+
(match_arm
52+
"then" @indent @extend
53+
then: (_) @anchor
54+
(#not-same-line? @indent @anchor)
55+
)
56+
57+
[
58+
"}"
59+
"]"
60+
")"
61+
] @outdent

runtime/queries/koto/injections.scm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
((comment) @injection.content
2+
(#set! injection.language "comment"))

runtime/queries/koto/locals.scm

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
; Scopes
2+
(module (_) @local.scope)
3+
4+
(function
5+
body: (_) @local.scope)
6+
7+
; Definitions
8+
(assign
9+
lhs: (identifier) @local.definition)
10+
11+
(variable
12+
(identifier) @local.definition)
13+
14+
(arg
15+
(identifier) @local.definition)
16+
17+
(arg
18+
(variable (identifier)) @local.definition)
19+
20+
(import_item
21+
(identifier) @local.definition)
22+
23+
(entry_block
24+
(identifier) @local.definition)
25+
26+
(entry_inline
27+
(identifier) @local.definition)
28+
29+
; References
30+
(identifier) @local.reference

runtime/queries/koto/textobjects.scm

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
(comment) @comment.inside
2+
3+
(comment)+ @comment.around
4+
5+
(function
6+
body: (_) @function.inside) @function.around
7+
8+
(args
9+
((arg) @parameter.inside . ","? @parameter.around) @parameter.around)
10+
11+
(call_args
12+
((call_arg) @parameter.inside . ","? @parameter.around) @parameter.around)
13+
14+
(chain
15+
call: (tuple
16+
((element) @parameter.inside . ","? @parameter.around) @parameter.around))
17+
18+
(map
19+
((entry_inline) @entry.inside . ","? @entry.around) @entry.around)
20+
21+
(map_block
22+
((entry_block) @entry.inside) @entry.around)
23+
24+
(list
25+
((element) @entry.inside . ","? @entry.around) @entry.around)
26+
27+
(tuple
28+
(_) @entry.around)
29+
30+
(assign
31+
(meta (test))
32+
(function body: (_) @test.inside)
33+
) @test.around
34+
35+
(entry_block
36+
key: (meta (test))
37+
value: (function body: (_) @test.inside)
38+
) @test.around

0 commit comments

Comments
 (0)