andymass / vim-matchup

vim match-up: even better % :facepunch: navigate and highlight matching words :facepunch: modern matchit and matchparen. Supports both vim and neovim + tree-sitter.
https://www.vim.org/scripts/script.php?script_id=5624
MIT License
1.71k stars 73 forks source link

'Invalid node type "where"' error in Haskell files #347

Closed gregorias closed 6 months ago

gregorias commented 6 months ago

Explain the issue

This plugin started recently throwing errors in Haskell files. I think it started with https://github.com/nvim-treesitter/nvim-treesitter/commit/da0efd7398713a3177da5ce8690f0e5c5415763d, where the parser recently dropped the where node (https://github.com/tree-sitter/tree-sitter-haskell/commit/f8e8da7f1ee26c97160036355223c745e34fc6be), which vim-matchup still uses in its Haskell queries (for example, at https://github.com/andymass/vim-matchup/blob/2d660e4aa7c566014c667af2cda0458043527902/after/queries/haskell/matchup.scm#L4).

Reproduction

I’m using Neovim 0.10 with tree-sitter.

  1. Create Foo.hs
pull :: (MonadIO m) => m ()
pull = do
    return ()
  where
    foo = 1
  1. Open the file.
nvim Foo.hs
  1. Press j to move one line down.

You’ll see the following error:

Error detected while processing CursorMoved Autocommands for "*"..function 3[3]..4[71]..matchup#delim#get_current[1]..<SNR>33_get_delim_multi[3]..matchup#ts_engine#get_delim[3]
..<SNR>29_forward:                                                                                                                                                              
line    1:                                                                                                                                                                      
E5108: Error executing lua ...m/0.10.0/share/nvim/runtime/lua/vim/treesitter/query.lua:252: Query error at 4:4. Invalid node type "where":                                      
  (where) @mid.module.1                                                                                                                                                         
   ^                                                                                                                                                                            

stack traceback:                                                                                                                                                                
        [C]: in function '_ts_parse_query'                                                                                                                                      
        ...m/0.10.0/share/nvim/runtime/lua/vim/treesitter/query.lua:252: in function 'fn'                                                                                       
        ...ovim/0.10.0/share/nvim/runtime/lua/vim/func/_memoize.lua:58: in function 'fn'                                                                                        
        ...ovim/0.10.0/share/nvim/runtime/lua/vim/func/_memoize.lua:58: in function 'get_query'                                                                                 
        ...vim-matchup/lua/treesitter-matchup/third-party/query.lua:55: in function 'get_query'                                                                                 
        ...vim-matchup/lua/treesitter-matchup/third-party/query.lua:142: in function 'prepare_query'                                                                            
        ...vim-matchup/lua/treesitter-matchup/third-party/query.lua:339: in function 'iter_group_results'                                                                       
        ...vim-matchup/lua/treesitter-matchup/third-party/query.lua:351: in function 'collect_group_results'                                                                    
        ...vim/lazy/vim-matchup/lua/treesitter-matchup/internal.lua:46: in function 'fn'                                                                                        
        ...0/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:491: in function 'for_each_tree'                                                                            
        ...vim/lazy/vim-matchup/lua/treesitter-matchup/internal.lua:40: in function 'fn'                                                                                        
        ...im/lazy/nvim-treesitter/lua/nvim-treesitter/ts_utils.lua:380: in function 'get_matches'                                                                              
        ...vim/lazy/vim-matchup/lua/treesitter-matchup/internal.lua:102: in function 'fn'                                                                                       
        ...im/lazy/nvim-treesitter/lua/nvim-treesitter/ts_utils.lua:380: in function 'get_active_nodes'                                                                         
        ...vim/lazy/vim-matchup/lua/treesitter-matchup/internal.lua:221: in function 'get_delim'                                                                                
        [string "luaeval()"]:1: in main chunk 

Minimal init.lua file

Please provide a minimal vimrc file that reproduces the issue. The following should often suffice:

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({
        "git",
        "clone",
        "--filter=blob:none",
        "https://github.com/folke/lazy.nvim.git",
        "--branch=stable",
        lazypath,
    })
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
    {
        [1] = "andymass/vim-matchup",
    },
    {
        [1] = "nvim-treesitter/nvim-treesitter",
        config = function()
            local config_table = {
                ensure_installed = "haskell",
                matchup = {
                    enable = true,
                },
            }

            require("nvim-treesitter.configs").setup(config_table)
        end,
    },
})
gregorias commented 6 months ago

https://github.com/nvim-treesitter/nvim-treesitter/pull/6580 even mentions that this plugin needs an update.

andymass commented 6 months ago

Removed where for now to prevent the error, if it can be added back somehow, I will appreciate a PR