Query: invalid node type at position 1400 for language rust
fikovnik opened this issue · comments
Describe the bug
After installing nvim-treesitter-textobject, I get the following error on every rust file:
Error detected while processing BufReadPost Autocommands for "*":
Error executing lua callback: /usr/share/nvim/runtime/filetype.lua:22: Error executing lua: /usr/share/nvim/runtime/
filetype.lua:23: Vim(append):Error executing lua callback: /usr/share/nvim/runtime/lua/vim/treesitter/query.lua:219:
query: invalid node type at position 1400 for language rust
stack traceback:
[C]: in function '_ts_parse_query'
/usr/share/nvim/runtime/lua/vim/treesitter/query.lua:219: in function 'get_query'
...cker/start/nvim-treesitter/lua/nvim-treesitter/query.lua:104: in function 'get_query'
...r-textobjects/lua/nvim-treesitter/textobjects/attach.lua:9: in function 'attach'
...er/start/nvim-treesitter/lua/nvim-treesitter/configs.lua:505: in function 'attach_module'
...er/start/nvim-treesitter/lua/nvim-treesitter/configs.lua:528: in function 'reattach_module'
...er/start/nvim-treesitter/lua/nvim-treesitter/configs.lua:131: in function <...er/start/nvim-treesitter/lu
a/nvim-treesitter/configs.lua:130>
To Reproduce
- Install the plugin
- Open any rust file
Expected behavior
No errors
Output of :checkhealth nvim-treesitter
nvim-treesitter: require("nvim-treesitter.health").check()
Installation
- OK:
tree-sitter
found 0.20.7 (parser generator, only needed for :TSInstallFromGrammar)
- OK:
node
found v19.0.0 (only needed for :TSInstallFromGrammar)
- OK:
git
executable found.
- OK:
cc
executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
Version: cc (GCC) 12.2.0
- OK: Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.
Parser/Features H L F I J
- cpp ✓ ✓ ✓ ✓ ✓
- dockerfile ✓ . . . ✓
- html ✓ ✓ ✓ ✓ ✓
- yaml ✓ ✓ ✓ ✓ ✓
- c ✓ ✓ ✓ ✓ ✓
- make ✓ . ✓ . ✓
- r ✓ ✓ . ✓ ✓
- scala ✓ . ✓ . ✓
- lua ✓ ✓ ✓ ✓ ✓
- bash ✓ ✓ ✓ . ✓
- toml ✓ ✓ ✓ ✓ ✓
- rust ✓ ✓ ✓ ✓ ✓
Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
+) multiple parsers found, only one will be used
x) errors found in the query, try to run :TSUpdate {lang}
Output of nvim --version
NVIM v0.8.0
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by builduser
Features: +acl +iconv +tui
See ":help feature-compile"
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/usr/share/nvim"
Run :checkhealth for more info
Additional context
It used to work just fine, until today when I did PackerSync.
This seems to come from #nvim-treesitter/nvim-treesitter@dd89caf which includes #tree-sitter/tree-sitter-rust#152. This removes the if_let_expression
token.
If I understand correctly, if let
expressions are now parsed as normal if
and a token let_condition
was added to treat cases like if let
or while let
.
Here's my temporary fix:
Save the following patch file somewhere (in this example as fix.patch):
diff --git a/queries/rust/textobjects.scm b/queries/rust/textobjects.scm
index a5cb528..28ef74f 100644
--- a/queries/rust/textobjects.scm
+++ b/queries/rust/textobjects.scm
@@ -47,15 +47,15 @@
(match_expression) @conditional.outer
-(if_let_expression
- consequence: (block)?
- @conditional.inner) @conditional.outer
+; (if_let_expression
+; consequence: (block)?
+; @conditional.inner) @conditional.outer
-(if_let_expression
- alternative: (else_clause (block) @conditional.inner))
+; (if_let_expression
+; alternative: (else_clause (block) @conditional.inner))
-(if_let_expression
- pattern: (_) @conditional.inner)
+; (if_let_expression
+; pattern: (_) @conditional.inner)
;; loops
(loop_expression
@@ -64,8 +64,8 @@
(while_expression
(_)? @loop.inner) @loop.outer
-(while_let_expression
- (_)? @loop.inner) @loop.outer
+; (while_let_expression
+; (_)? @loop.inner) @loop.outer
(for_expression
body: (block)? @loop.inner) @loop.outer
@@ -138,10 +138,10 @@
. (_) @parameter.inner . ","? @_end)
(#make-range! "parameter.outer" @parameter.inner @_end))
-((meta_arguments
- "," @_start . (_) @parameter.inner)
- (#make-range! "parameter.outer" @_start @parameter.inner))
-((meta_arguments
- . (_) @parameter.inner . ","? @_end)
- (#make-range! "parameter.outer" @parameter.inner @_end))
+; ((meta_arguments
+; "," @_start . (_) @parameter.inner)
+; (#make-range! "parameter.outer" @_start @parameter.inner))
+; ((meta_arguments
+; . (_) @parameter.inner . ","? @_end)
+; (#make-range! "parameter.outer" @parameter.inner @_end))
Then in a terminal, run:
cd $HOME/.local/share/nvim/site/pack/packer/start/nvim-treesitter-textobjects # may differ depending on your package manager
patch queries/rust/textobjects.scm /PATH/TO/fix.patch
Or just touch ~/.config/nvim/queries/rust/textobjects.scm