Add Roto to list of supported languages

See https://github.com/NLnetLabs/tree-sitter-roto for the parser repo.

This only works if the filetype for Roto is added explicitly:

```lua
vim.filetype.add({ extension = { roto = "roto" } })
```

After that the queries seem to work well when testing it on all the
example Roto scripts from https://github.com/NLnetLabs/roto/tree/main/examples.

I have a [PR to Vim](https://github.com/vim/vim/pull/19195) aiming to
add `.roto` as a recognized extension for a `roto` filetype. Once there,
NeoVim should eventually pull it in and users will not need to add the
filetype themselves.
This commit is contained in:
Bendik Samseth 2026-01-17 09:46:48 +01:00
parent 8aada0e394
commit fef24d6956
No known key found for this signature in database
7 changed files with 193 additions and 0 deletions

View file

@ -249,6 +249,7 @@ jsx (queries only)[^jsx] | unstable | `HFIJ ` | @steelsojka
[robots_txt](https://github.com/opa-oz/tree-sitter-robots-txt) | unstable | `H  J ` | @opa-oz
[roc](https://github.com/faldor20/tree-sitter-roc) | unstable | `H IJL` | @nat-418
[ron](https://github.com/tree-sitter-grammars/tree-sitter-ron) | unstable | `HFIJL` | @amaanq
[roto](https://github.com/NLnetLabs/tree-sitter-roto) | unstable | `H   L` | @bsamseth
[rst](https://github.com/stsewd/tree-sitter-rst) | unstable | `H  JL` | @stsewd
[ruby](https://github.com/tree-sitter/tree-sitter-ruby) | unstable | `HFIJL` | @TravonteD
[runescript](https://github.com/2004Scape/tree-sitter-runescript) | unstable | `H  J ` | @2004Scape

View file

@ -1954,6 +1954,15 @@ return {
maintainers = { '@amaanq' },
tier = 2,
},
roto = {
install_info = {
branch = 'main',
revision = '9ac03409ddee6ab8f3b74746756f12fc6adec740',
url = 'https://github.com/NLnetLabs/tree-sitter-roto',
},
maintainers = { '@bsamseth' },
tier = 2,
},
rst = {
install_info = {
revision = '4e562e1598b95b93db4f3f64fe40ddefbc677a15',

View file

@ -0,0 +1,111 @@
; Identifiers
(identifier) @variable
; Assume that uppercase names in paths are types
((identifier) @type
(#match? @type "^[A-Z]"))
(optional_type) @type
(type_name) @type
(unit) @type.builtin
(never) @type.builtin
(record_type) @type
(type_name
(path
(identifier) @type.builtin)
(#match? @type.builtin "^(u8|u16|u32|u64|i8|i16|i32|i64|f32|f64|String|bool|Asn|IpAddr|Prefix)$"))
; Assume all-caps names are constants
((identifier) @constant
(#match? @constant "^[A-Z][A-Z\\d_]+$'"))
; Function calls
; Unfortunately, we can't really distinguish them from methods if it's called
; on a path
(call_expression
function: (path
(identifier) @function .))
(call_expression
function: (access_expression
(identifier) @function.method .))
; Calling a function with an uppercase letter: it's an enum constructor
(call_expression
function: (path
(identifier) @constructor .)
(#match? @constructor "^[A-Z]"))
; Function definitions
(function_item
(identifier) @function)
(filtermap_item
(identifier) @function)
(test_item
(identifier) @function)
(line_comment) @comment
(parameter
(identifier) @variable.parameter)
[
"*"
"="
"=="
"!="
"&&"
"|"
"||"
"-"
"+"
"/"
">"
"<"
">="
"<="
"?"
] @operator
[
"("
")"
"{"
"}"
"["
"]"
] @punctuation.bracket
[
":"
"."
","
";"
"->"
] @punctuation.delimiter
[
"filter"
"filtermap"
"fn"
"test"
] @keyword.function
"in" @keyword
; "dep" @keyword
; "std" @keyword
; "super" @keyword
; "pkg" @keyword
"not" @keyword.operator
(string_literal) @string
(unit_literal) @constant.builtin

View file

@ -0,0 +1,17 @@
[
(function_item)
(filtermap_item)
(test_item)
(block)
] @local.scope
(let_statement
(identifier) @local.definition)
(parameter
(identifier) @local.definition)
(for_expression
(identifier) @local.definition)
(identifier) @local.reference

View file

@ -0,0 +1,23 @@
(function_item
"fn" @context
name: (_) @name) @item
(filtermap_item
"filtermap" @context
name: (_) @name) @item
(filtermap_item
"filter" @context
name: (_) @name) @item
(record_item
"record" @context
name: (_) @name) @item
(variant_item
"variant" @context
name: (_) @name) @item
(test_item
"test" @context
name: (_) @name) @item

View file

@ -0,0 +1,14 @@
(function_item
name: (identifier) @definition.function)
(filtermap_item
name: (identifier) @definition.function)
(test_item
name: (identifier) @definition.function)
(record_item
name: (identifier) @definition.type)
(variant_item
name: (identifier) @definition.type)

View file

@ -0,0 +1,18 @@
(function_item
body: (block) @function.inside) @function.around
(filtermap_item
body: (block) @function.inside) @function.around
(test_item
body: (block) @test.inside) @test.around
(record_item
fields: (record_type) @class.inside) @class.around
(variant_item
constructors: (variant_constructors) @class.inside) @class.around
(line_comment) @comment.inside
(line_comment)+ @comment.around