kickstart.nvim
kickstart.nvim copied to clipboard
Treesitter crashes on [[ ]] lua syntax in init.lua
It seems that whenever the [[ xxx ]] pattern is encountered in init.lua is encountered, TS crashes with the following back trace:
ERR 2022-12-17T09:36:32.033 nvim.63645.0 decor_provider_invoke:38: error in provider treesitter/highlighter:line: Error executing lua: ...im/0.8.0/share/nvim/runtime/lua/vim/treesitter/query.lua:219: query: invalid node type at position 2765 for language vim stack traceback: [C]: in function '_ts_parse_query' ...im/0.8.0/share/nvim/runtime/lua/vim/treesitter/query.lua:219: in function 'get_query' ....0/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:36: in function 'new' ....0/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:160: in function 'get_query' ....0/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:182: in function 'fn' ...0/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:210: in function 'for_each_tree' ...0/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:214: in function 'for_each_tree' ....0/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:168: in function 'on_line_impl' ....0/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:231: in function <....0/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:225>
Happend both on nvim 0.8.0 and 0.8.1 - I have not had this issue with my previous config which happily parsed any lua file.
I have this issue as well. It's because you're in a .lua file but there's also .vim syntax present. If I remember correctly, I would :TSUpdate vim and it would resolve it.
Thank you @MichaelVessia this solved it for me.
Next time I opened nvim the problem returned.
I noticed this too on a fresh install today, but :TSUpdate vim has fixed it for me
:TSUpdate vim seems to have resolved it for me as well, but keeping the issue open as it seems common enough that it should probably be worked around in the bootstrap code.
So just to make sure we're clear, after running :TSUpdate vim the problem was resolved?
Correct.
It did not fix it for me. But this predates my starting over with configuration using this repo.
here is the current output from checkhealth
nvim-treesitter: require("nvim-treesitter.health").check()
Installation
- WARNING:
tree-sitterexecutable not found (parser generator, only needed for :TSInstallFromGrammar, not required for :TSInstall) - OK:
nodefound v18.12.1 (only needed for :TSInstallFromGrammar) - OK:
gitexecutable found. - OK:
ccexecutable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" } Version: cc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0 - OK: Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.
OS Info:
{ machine = "x86_64", release = "6.0.6-76060006-generic", sysname = "Linux", version = "#202210290932~1669062050~22.04~d94609a SMP PREEMPT_DYNAMIC Mon N" }
Parser/Features H L F I J
- regex ✓ . . . .
- go ✓ ✓ ✓ ✓ ✓
- json ✓ ✓ ✓ ✓ .
- vim x ✓ ✓ . ✓
- comment ✓ . . . .
- lua ✓ ✓ ✓ ✓ ✓
- html ✓ ✓ ✓ ✓ ✓
- bash ✓ ✓ ✓ . ✓
- javascript ✓ ✓ ✓ ✓ ✓
- gitattributes ✓ . . . ✓
- git_rebase ✓ . . . ✓
- python ✓ ✓ ✓ ✓ ✓
- gitcommit ✓ . . . ✓
- typescript ✓ ✓ ✓ ✓ ✓
- help ✓ . . . ✓
- mermaid ✓ . . . .
- yaml ✓ ✓ ✓ ✓ ✓
- c_sharp ✓ ✓ ✓ . ✓
- markdown ✓ . ✓ . ✓
- c ✓ ✓ ✓ ✓ ✓
- rust ✓ ✓ ✓ ✓ ✓
- cpp ✓ ✓ ✓ ✓ ✓
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}
The following errors have been detected:
- ERROR: vim(highlights): /usr/local/share/nvim/runtime/lua/vim/treesitter/query.lua:171: query: invalid node type at position 4647 for language vim vim(highlights) is concatenated from the following files: | [OK]:"/home/moose/.local/share/nvim/site/pack/packer/start/nvim-treesitter/queries/vim/highlights.scm" | [ERROR]:"/usr/local/share/nvim/runtime/queries/vim/highlights.scm", failed to load: /usr/local/share/nvim/runtime/lua/vim/treesitter/query.lua:171: query: invalid node type at position 581 for language vim
I was able to work around it using this syntax.
vim.cmd{ cmd='packadd packer.nvim'}
@agentHoover I have this in my notes, if it's helpful:
-- If seeing errors parsing, check that you do not have two parsers installed. Why this happens I do not know.
-- :echo nvim_get_runtime_file('*/python.so', v:true)
-- rm -rf /usr/local/lib/nvim/parser
I'm still learning about treesitter so I don't know why this happens, but it seems like two highlights.scm files sometimes exist, as it seems to be in your case, and then it doesn't know which to use.
@MichaelVessia yep. That fixed it. I tried to uninstall the vim parser with TSUninstall vim and it told me that vim was still installed and exactly which file to remove manually to uninstall it. Removed the file, reinstalled, and all is well. The file I removed was located here: /usr/local/lib/nvim/parser/vim.so for what its worth.
Thanks for your help.
Adding vim to the ensure_installed list for treesitter seems to resolve this problem as well (and persistently across restarts).
https://github.com/nvim-lua/kickstart.nvim/blob/master/init.lua#L221
Follow-up: The lua queries from nvim-treesitter contain injections referencing vim. I guess this is causing the problem. Although I am not sure if missing the referenced injections "should" crash the parser or if this is some other bug. At least adding lua and not vim to treesitter (like the kickstart does), seems to be the cause for the errors.
I had the same issue and fixed adding 'vim' to ensure_installed.. Maybe we should add 'vim' to that array by default. Are there drawbacks to adding it?
:sweat: just that I thought I already had vim in the list haha
If someone wants a free PR, they can open. Otherwise I'll do probably tomorrow or soon
I have investigated these two treesitter situations...
Situation 1
After installing vim parser no more treesitter (2) errors: init.lua: vim.cmd [[packadd packer.nvim]] vim.cmd [[colorscheme onedark]]
Situation 2
Example 01 (commands-GOOD.lua):
vim.cmd( [[
" ------------------------ COMMANDS --------------------------
" ----------------------------------------------------------
" Comm_ 01:
" Edit init.vim and cd to folder:
command! QeditVIMRC :e $MYVIMRC | tcd %:h
" ----------------------------------------------------------
" Comm_ 02:
" Toggle line relativenumber on or off.
command! QnumberRelativ set relativenumber!
" ----------------------------------------------------------
]] )
Example 02 (commands-BAD.lua):
When you move the cursor slowly from the first row down, then you can see that the treesitter is not working well.
vim.cmd [[
" ------------------------ COMMANDS --------------------------
" ----------------------------------------------------------
" Comm_ 01:
" Edit init.vim and cd to folder:
command! QeditVIMRC :e $MYVIMRC | tcd %:h
" ----------------------------------------------------------
" Comm_ 02:
" Toggle line relativenumber on or off.
command! QnumberRelativ set relativenumber!
" ----------------------------------------------------------
]]
Desktop:
- OS: Windows 10
- Terminal: no, nvim-qt.exe
** Neovim Version **
- Output of running
:versionfrom inside of neovim:
NVIM v0.8.2 Build type: RelWithDebInfo LuaJIT 2.1.0-beta3 Compiled by runneradmin@fv-az28-353
Features: -acl +iconv +tui See ":help feature-compile"
system vimrc file: "$VIM\sysinit.vim" fall-back for $VIM: "C:/Program Files (x86)/nvim/share/nvim"
Should have all the required grammars now, so I can't reproduce crash anymore. Thanks!