postsolar / tree-sitter-kanata

Kanata grammar for Tree-sitter
2 stars 0 forks source link

Highlight not working neovim #1

Open DarkKronicle opened 3 weeks ago

DarkKronicle commented 3 weeks ago

Hello! I'm having some difficulty getting the highlighting to work in neovim. I've installed from latest commit, and have moved the queries/highlights.scm to queries/kanata/highlights.scm in a neovim sourced folder so that treesitter will properly find it.

When I open up any kanata file, this message gets spammed several hundred times. The parsing of the tree seems to work though (using :InspectTree) image

Error in decoration provider treesitter/highlighter.line:
Error executing lua: ...d-0.10.0/share/nvim/runtime/lua/vim/treesitter/query.lua:331: couldn't parse regex: Vim:E866: (NFA regexp) Misplaced @
stack traceback:
    [C]: in function 'regex'
    ...d-0.10.0/share/nvim/runtime/lua/vim/treesitter/query.lua:331: in function '__index'
    ...d-0.10.0/share/nvim/runtime/lua/vim/treesitter/query.lua:348: in function 'handler'
    ...d-0.10.0/share/nvim/runtime/lua/vim/treesitter/query.lua:767: in function 'fn'
    ...pped-0.10.0/share/nvim/runtime/lua/vim/func/_memoize.lua:58: in function 'match_preds'
    ...d-0.10.0/share/nvim/runtime/lua/vim/treesitter/query.lua:883: in function 'iter'
    ....0/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:310: in function 'fn'
    ....0/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:210: in function 'for_each_highlight_state'
    ....0/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:291: in function 'on_line_impl'
    ....0/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:367

My guess is it is this line. Running :echo matchstr('@hello', '\@\.\+') produces the same error.

Looking into it a bit, it seems that vim has some weird regex syntax. Using

  (#match? @string.special.symbol "\\V@\\.\\+"))

Seems to fix the issue

postsolar commented 3 weeks ago

Hello, and thank you for investigating this

I'm not a Vim/Neovim user myself so I didn't test the queries on it, in fact they're not meant to be compatible with Vim at all because the capture group names (@string, @keyword, etc) are different across different editors

Is it the only issue you've found with these queries? If so, we could perhaps create a separate vim_queries/ directory in the repo to be used by Vim users, with proper capture groups names and proper regex

DarkKronicle commented 3 weeks ago

That was the only one that seemed to error out, but I noticed if you have a block comment with some keywords in it, it would break the parser.

#|
(defsrc 
  1 2 3 4
)
|#

(deflayer...)

The defsrc would be highlighted, and then the rest of the text would not have any highlights. Looking in InspectTree, a lot of the objects were shown as ERROR.

postsolar commented 3 weeks ago

Yes, I can reproduce it. Looks like it's not Vim-specific but a problem with block comments parsing. The contents of the comments shouldn't be parsed at all, but for some reason they do :thinking: