bamonroe/rnoweb-nvim

Errors with `superscript` and `subscript` queries.

Closed this issue · 2 comments

Recently, after updating tree-sitter, I've been getting the following error.

Error detected while processing CursorHold Autocommands for "*.tex":
Error executing lua callback: /usr/share/nvim/runtime/lua/vim/treesitter/query.lua:252: Query error at 2:7. Impossible pattern:
      (word) @tval (#set! @tval "kind" "superscript")
      ^

stack traceback:
        [C]: in function '_ts_parse_query'
        /usr/share/nvim/runtime/lua/vim/treesitter/query.lua:252: in function 'fn'
        /usr/share/nvim/runtime/lua/vim/func/_memoize.lua:58: in function 'parse'
        /home/venatio/rnoweb-nvim/lua/rnoweb-nvim/symbols.lua:683: in function 'get_queries'
        /home/venatio/rnoweb-nvim/lua/rnoweb-nvim/init.lua:122: in function 'fn'
        /usr/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:491: in function 'for_each_tree'
        /home/venatio/rnoweb-nvim/lua/rnoweb-nvim/init.lua:118: in function 'mask_texsym'
        /home/venatio/rnoweb-nvim/lua/rnoweb-nvim/init.lua:152: in function 'refresh'
        /home/venatio/rnoweb-nvim/plugin/init.lua:27: in function </home/venatio/rnoweb-nvim/plugin/init.lua:22>

So the two offending queries are:

table.insert(M.queries.latex, {
  fn = "subsuper",
  query = [[
    (superscript
    (word) @tval (#set! @tval "kind" "superscript")
    )
  ]],
})

table.insert(M.queries.latex, {
  fn = "subsuper",
  query = [[
    (subscript
    (word) @tval (#set! @tval "kind" "subscript")
    )
  ]],
})

and if I replace them with a more general approach to match child nodes:

table.insert(M.queries.latex, {
  fn = "subsuper",
  query = [[
    (superscript
    (_) @tval
    (#set! @tval "kind" "superscript")
    )
  ]],
})

table.insert(M.queries.latex, {
  fn = "subsuper",
  query = [[
    (subscript
    (_) @tval
    (#set! @tval "kind" "subscript")
    )
  ]],
})

I haven't noticed any difference with using this new pattern match, to the previous one (before the errors), but perhaps that's due to the use I've given them.

Feel free to let me know if this is an isolated issue on my part, otherwise I'll gladly introduce a PR.

Thanks for the issue report! Please do open a pull request. I'll be able to test it in a few other environments easily. If I don't find any conflicts I'll merge it in.

Fixed with #6