nvim-lua / kickstart.nvim

A launch point for your personal nvim configuration
MIT License
20.19k stars 24.67k forks source link

Treesitter crashes on [[ ]] lua syntax in init.lua #48

Closed kalleh closed 1 year ago

kalleh commented 1 year ago

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.

MichaelVessia commented 1 year ago

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.

agentHoover commented 1 year ago

Thank you @MichaelVessia this solved it for me. Next time I opened nvim the problem returned.

MitchRivet commented 1 year ago

I noticed this too on a fresh install today, but :TSUpdate vim has fixed it for me

kalleh commented 1 year ago

: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.

tjdevries commented 1 year ago

So just to make sure we're clear, after running :TSUpdate vim the problem was resolved?

kalleh commented 1 year ago

Correct.

agentHoover commented 1 year ago

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

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

The following errors have been detected:

I was able to work around it using this syntax. vim.cmd{ cmd='packadd packer.nvim'}

MichaelVessia commented 1 year ago

@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.

agentHoover commented 1 year ago

@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.

sven-strothoff commented 1 year ago

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.

fox1t commented 1 year ago

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?

tjdevries commented 1 year ago

: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

mlabrkic commented 1 year ago

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:

Neovim Version

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"

tjdevries commented 1 year ago

Should have all the required grammars now, so I can't reproduce crash anymore. Thanks!