tree-sitter-grammars / tree-sitter-markdown

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

Error: query: invalid node type at position 152 #50

Closed ibhagwan closed 2 years ago

ibhagwan commented 2 years ago

Hi again @MDeiml,

I seem to encounter a new error when using the markdown parser with the nightly, using get_string_parser fails:

vim.treesitter.get_string_parser("test", "cpp")              -- success
vim.treesitter.get_string_parser("test", "markdown_inline")  -- success
vim.treesitter.get_string_parser("test", "markdown")         -- FAIL

With error:

The reason the runtime paths are weird is because I'm using the nightly appimage

E5108: Error executing lua ...488e/usr/share/nvim/runtime/lua/vim/treesitter/query.lua:174: query: invalid node type at position 152
stack traceback:
[C]: in function '_ts_parse_query'
...488e/usr/share/nvim/runtime/lua/vim/treesitter/query.lua:174: in function 'get_query'
...r/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:35: in function 'get_string_parser'
.../site/pack/vendor/start/ts-vimdoc.nvim/lua/ts-vimdoc.lua:23: in function 'docgen'
[string ":lua"]:1: in main chunk
MDeiml commented 2 years ago

Can you share the queries you are using? It seems they might be outdated.

MDeiml commented 2 years ago

(Btw table support is taking some time, but now with the split grammars I'm kinda getting there)

ibhagwan commented 2 years ago

Can you share the queries you are using? It seems they might be outdated.

This also happens with my vimdoc generation script that downloads a new instance of the nightly/treesitter and parsers, so I would assume it also downloads the latest scm file.

(Btw table support is taking some time, but now with the split grammars I'm kinda getting there)

That would be amazing :)

MDeiml commented 2 years ago

Hm, the scm files from this repo or the ones from nvim-treesitter? The ones here use slightly different capture names (ones compatible with https://github.com/tree-sitter/tree-sitter/tree/master/highlight) which are not compatible with neovim. But the error you are getting is suggesting that the query contains a node that is not part of the grammar. So I don't think that's the problem.

I would guess that the scm files are outdated. They should be up to date with the ones in nvim-treesitter. You can check them with :TSEditQuery highlights markdown / :TSEdirQueryUserAfter highlights markdown. Maybe it's also a problem with the injections query file instead of highlights.

ibhagwan commented 2 years ago

Hm, the scm files from this repo or the ones from nvim-treesitter? The ones here use slightly different capture names (ones compatible with https://github.com/tree-sitter/tree-sitter/tree/master/highlight) which are not compatible with neovim. But the error you are getting is suggesting that the query contains a node that is not part of the grammar. So I don't think that's the problem.

I was using the default that comes with nvim-treesitter, I just tried two different troublehsooting steps:

  1. Downloaded the both injections and highlights from this plugin and placed them inside .config/nvim/after/queries/markdown
  2. Overwrote the contents of the local nvim-treesitter query file under .local/share/nvim/site/pack/packer/opt/nvim-treesitter/queries/markdown with the file frm this repo, this is the diff: image

Both fail with the exact same error, contents of the markdown doesn't seem to matter the call to get_string_parser always fails.

MDeiml commented 2 years ago

Hm, do you have (tree-sitter playground)[https://github.com/nvim-treesitter/playground] installed? If so what does it output if you open a markdown file with content

test

?

(Maybe you need to run :TSBufDisable highlights and :TSBufDisable injections so you don't get any errors)

ibhagwan commented 2 years ago

Hm, do you have tree-sitter playground, If so what does it output if you open a markdown file with content.

I do have playground installed, I also have this configured in my nvim-treesitter, and pressing <CR> to start the incremental selection would fail with the same error only inside a markdown file.

require'nvim-treesitter.configs'.setup {
  incremental_selection = {
    enable = true,
    keymaps = {
      init_selection = '<CR>',
      node_incremental = '<CR>',
      node_decremental = '<S-Tab>',
      scope_incremental = '<Tab>',
    },
  },
  ...

I also have good news, I just updated nvim-treesitter again and everyhing works again, I guess it was an issue with nvim-treesitter.