tree-sitter-grammars / tree-sitter-markdown

Markdown grammar for tree-sitter
MIT License
379 stars 45 forks source link

Errror: Ranges can on ly be made from 6 element long tables or nodes. #48

Closed ibhagwan closed 2 years ago

ibhagwan commented 2 years ago

Haven't investigated this fully yet but it seems to be related to the latest updates.

I'm using this parser to generate vimdoc from markdown, I've narrowed it down to the part of code that's failing:

this fails even with an empty file

local parser = vim.treesitter.get_string_parser(
-- contents of a sample markdown file consisting of 2 lines
-- tile and body
"# title\nbody\n\n",
"markdown"
)
parser:parse()

The call to parser:parse() fails with:

Error detected while processing /home/bhagwan/test.lua:
E5113: Error while calling lua chunk: /usr/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:115:
Ranges can only be made from 6 element long tables or nodes.
stack traceback:
[C]: in function 'set_included_ranges'
/usr/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:115: in function 'parse'
/usr/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:149: in function 'parse'
/home/bhagwan/test.lua:3: in main chunk
MDeiml commented 2 years ago

Hm, I can't reproduce that error. Are you running with the latest development version of vim? If not which version are you using?

ibhagwan commented 2 years ago

I ran this with neovim 7.0, I just tried with the nightly NVIM v0.8.0-dev+513-g01fc5097d and it errored out with the same error.

Is this not supposed to work with 7.0?

Something strange did happen with the nightly, I'm still gettitng the same error file path /usr/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:115: where the error should come from the AppImage mount folder (i.e. /tmp/.mount_nvim.adA0udF/usr/share/nvim/runtime in this case, somehow the AppImage is using the installed runtime (which is of version 7.0).

ibhagwan commented 2 years ago

Just updated my neovim to 7.2:

:version
NVIM v0.7.2
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by void-buildslave@a-fsn-de

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

Still getting the same exact error:

Error detected while processing /home/bhagwan/test.lua:
E5113: Error while calling lua chunk: /usr/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:115: Ra
nges can only be made from 6 element long tables or nodes.
stack traceback:
        [C]: in function 'set_included_ranges'
        /usr/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:115: in function 'parse'
        /usr/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:149: in function 'parse'
        /home/bhagwan/test.lua:7: in main chunk
MDeiml commented 2 years ago

Is this not supposed to work with 7.0?

It does need nightly neovim (or at least that's what I'm validating against) since 7.2 doesn't have all the functionality needed yet.

Something strange did happen with the nightly, I'm still gettitng the same error file path /usr/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:115: where the error should come from the AppImage mount folder (i.e. /tmp/.mount_nvim.adA0udF/usr/share/nvim/runtime in this case, somehow the AppImage is using the installed runtime (which is of version 7.0).

Yeah, it seems it is still using the 7.0 files, so the error is the same as it's specifically due to a change in languagetree.lua in the newest version.

In this case there should be somewhat of a solution though. You can run :TSEditQuery injections markdown and remove (#exclude_children! ... ) from all the queries. That will mean that parsing won't be accurate anymore, but for most cases you should be fine.

Or of course you could configure nvim-treesitter to use an earlier version that's still working.

ibhagwan commented 2 years ago

Thanks for the suggetsions @MDeiml, I was able to solve this by modifying lua's package.path, due to the new split between markdown and markdown_inline I also needed to create a new parser for the inline nodes and got my forked babelfish.vim parser to work again, ty for maintaining this!