zbirenbaum / neodim

Neovim plugin for dimming the highlights of unused functions, variables, parameters, and more
315 stars 10 forks source link

[Bug] Treesitter error on leaving neovim #11

Closed akinsho closed 1 year ago

akinsho commented 2 years ago

I've noticed that when leaving neovim, I occasionally encounter the following error

Error executing vim.schedule lua callback: ...-72877bb/share/nvim/runtime/lua/vim/treesitter/query.lua:434: bad argument #1 to 'handler' (string expected, got nil)
stack traceback:
    [C]: in function 'handler'
    ...-72877bb/share/nvim/runtime/lua/vim/treesitter/query.lua:434: in function 'match_preds'
    ...-72877bb/share/nvim/runtime/lua/vim/treesitter/query.lua:519: in function '(for generator)'
    ...e/nvim/site/pack/packer/start/neodim/lua/neodim/util.lua:27: in function 'fn'
    ...b/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:192: in function 'for_each_tree'
    ...e/nvim/site/pack/packer/start/neodim/lua/neodim/util.lua:12: in function 'get_treesitter_nodes'
    ...e/nvim/site/pack/packer/start/neodim/lua/neodim/init.lua:22: in function 'get_ts_group'
    ...e/nvim/site/pack/packer/start/neodim/lua/neodim/init.lua:49: in function 'get_hl'
    ...e/nvim/site/pack/packer/start/neodim/lua/neodim/init.lua:55: in function 'create_diagnostic_extmark'
    ...e/nvim/site/pack/packer/start/neodim/lua/neodim/init.lua:190: in function 'show'
    ...e/nvim/site/pack/packer/start/neodim/lua/neodim/init.lua:204: in function ''
    vim/_editor.lua: in function ''
    vim/_editor.lua: in function <vim/_editor.lua:0>% 

It isn't related to diagnostics but to treesitter and seems to be from some value not being as expected. I think nil is slipping through somewhere.

I tried adding on neodim/utils.lua:12

image

But that didn't work. Not sure what else might be nil thought you might have an idea.

FWIW I'm on NVIM v0.8.0-dev+2034-g72877bb17

zbirenbaum commented 2 years ago

I've been looking into this but having trouble finding the cause. I'm pretty sure there's something that needs to be vim.schedule'd but I'm not sure what. It's possible that it's caused by neovim exiting during a call, since I only see the error on exit, and the printing to terminal stdout suggests that io has been changed prior to the error.

zbirenbaum commented 2 years ago

I've been looking into this but having trouble finding the cause. I'm pretty sure there's something that needs to be vim.schedule'd but I'm not sure what. It's possible that it's caused by neovim exiting during a call, since I only see the error on exit, and the printing to terminal stdout suggests that io has been changed prior to the error.

Upon a little further thought, I think that the reason might be that the way I handle refresh in the hide function (for insert mode updates) creates delayed calls, which may be executing while neovim is trying to exit. Theres an is_exiting check function iirc so I'll try to play around with it.

zbirenbaum commented 2 years ago

I haven't seen this happen since the buffer valid fix, so I think it was related. I'm gonna close this but if it comes back up feel free to reopen.

towry commented 1 year ago

I am having this error too.

Error executing vim.schedule lua callback: ...-a0dd663/share/nvim/runtime/lua/vim/treesitter/query.lua:499: bad argument #1 to 'handler' (string expected, got nil)
stack traceback:
        [C]: in function 'handler'
        ...-a0dd663/share/nvim/runtime/lua/vim/treesitter/query.lua:499: in function 'match_preds'
        ...-a0dd663/share/nvim/runtime/lua/vim/treesitter/query.lua:584: in function '(for generator)'
        ...m/HEAD-a0dd663/share/nvim/runtime/lua/vim/treesitter.lua:239: in function 'fn'
        ...3/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:210: in function 'for_each_tree'
        ...3/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:214: in function 'for_each_tree'
        ...m/HEAD-a0dd663/share/nvim/runtime/lua/vim/treesitter.lua:217: in function 'capture_fn'
        ...are/nvim/site/pack/packer/opt/neodim/lua/neodim/util.lua:27: in function 'get_treesitter_nodes'
        ...are/nvim/site/pack/packer/opt/neodim/lua/neodim/init.lua:22: in function 'get_ts_group'
        ...are/nvim/site/pack/packer/opt/neodim/lua/neodim/init.lua:49: in function 'get_hl'
        ...are/nvim/site/pack/packer/opt/neodim/lua/neodim/init.lua:55: in function 'create_diagnostic_extmark'
        ...are/nvim/site/pack/packer/opt/neodim/lua/neodim/init.lua:166: in fun   
dsully commented 1 year ago

Having the same error as @towry - almost the same stack trace:

Error executing vim.schedule lua callback: ...im/0.8.1/share/nvim/runtime/lua/vim/treesitter/query.lua:499: bad argument #2 to 'handler' (string expected, got nil)
stack traceback:
    [C]: in function 'handler'
    ...im/0.8.1/share/nvim/runtime/lua/vim/treesitter/query.lua:499: in function 'match_preds'
    ...im/0.8.1/share/nvim/runtime/lua/vim/treesitter/query.lua:584: in function '(for generator)'
    ...r/neovim/0.8.1/share/nvim/runtime/lua/vim/treesitter.lua:239: in function 'fn'
    ...1/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:210: in function 'for_each_tree'
    ...r/neovim/0.8.1/share/nvim/runtime/lua/vim/treesitter.lua:217: in function 'capture_fn'
    ...are/nvim/site/pack/packer/opt/neodim/lua/neodim/util.lua:27: in function 'get_treesitter_nodes'
    ...are/nvim/site/pack/packer/opt/neodim/lua/neodim/init.lua:22: in function 'get_ts_group'
    ...are/nvim/site/pack/packer/opt/neodim/lua/neodim/init.lua:49: in function 'get_hl'
    ...are/nvim/site/pack/packer/opt/neodim/lua/neodim/init.lua:55: in function 'create_diagnostic_extmark'
    ...are/nvim/site/pack/packer/opt/neodim/lua/neodim/init.lua:166: in function 'refresh'
    ...are/nvim/site/pack/packer/opt/neodim/lua/neodim/init.lua:200: in function 'hide'
    ...r/neovim/0.8.1/share/nvim/runtime/lua/vim/diagnostic.lua:1102: in function 'hide'
    ...r/neovim/0.8.1/share/nvim/runtime/lua/vim/diagnostic.lua:1423: in function 'reset'
    ...l/Cellar/neovim/0.8.1/share/nvim/runtime/lua/vim/lsp.lua:1142: in function <...l/Cellar/neovim/0.8.1/share/nvim/runtime/lua/vim/lsp.lua:1134>
zbirenbaum commented 1 year ago

Hmm, this looks like an issue with the lsp trying to run a function on a deleted buffer. Are you guys on nightly @towry @dsully? I'll build from source again and see if I can reproduce. I'll reopen this for now as well.

towry commented 1 year ago
❯ nvim --version
NVIM v0.9.0-dev-442+gb098e7971-dirty
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by towry@towryDeMiniMac.local

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/Cellar/neovim/HEAD-b098e79/share/nvim"

Run :checkhealth for more info

https://github.com/pze/nvim

zbirenbaum commented 1 year ago
❯ nvim --version
NVIM v0.9.0-dev-442+gb098e7971-dirty
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by towry@towryDeMiniMac.local

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/Cellar/neovim/HEAD-b098e79/share/nvim"

Run :checkhealth for more info

https://github.com/pze/nvim

Hmm, you are building from source too. What LSP is running when you run into the issue? I can't seem to reproduce this with clangd or sumneko.

Also can you link the file where your neodim config is? I couldn't find it in the repo you linked, and using github's code search function for 'neodim' turned up nothing too.

dsully commented 1 year ago

I am not building from source. Using 0.8.1 release/stable:

$ nvim --version
NVIM v0.8.1
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by brew@Ventura-arm64.local

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.8.1/share/nvim"

Run :checkhealth for more info

This happened with pyright for me IIRC.

Config:

    use({
        "zbirenbaum/neodim",
        config = function()
            require("neodim").setup({
                update_in_insert = {
                    enable = false,
                    delay = 100,
                },
                hide = {
                    virtual_text = false,
                    signs = false,
                    underline = true,
                },
            })
        end,
        event = "LspAttach",
    })
towry commented 1 year ago

Maybe not dim's issue, saw similar errors several times today.

towry commented 1 year ago
❯ nvim --version
NVIM v0.9.0-dev-442+gb098e7971-dirty
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by towry@towryDeMiniMac.local

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/Cellar/neovim/HEAD-b098e79/share/nvim"

Run :checkhealth for more info

https://github.com/pze/nvim

Hmm, you are building from source too. What LSP is running when you run into the issue? I can't seem to reproduce this with clangd or sumneko.

Also can you link the file where your neodim config is? I couldn't find it in the repo you linked, and using github's code search function for 'neodim' turned up nothing too.

@zbirenbaum the config https://github.com/pze/nvim/blob/cc851b7d577ede6195a004bdb461ee5399ae00d4/lua/overlays/coding.lua#L159

Newly log:


Error executing vim.schedule lua callback: ...-a0dd663/share/nvim/runtime/lua/vim/treesitter/query.lua:499: bad argument #1 to 'handler' (string expected, got nil)
stack traceback:
    [C]: in function 'handler'
    ...-a0dd663/share/nvim/runtime/lua/vim/treesitter/query.lua:499: in function 'match_preds'
    ...-a0dd663/share/nvim/runtime/lua/vim/treesitter/query.lua:584: in function '(for generator)'
    ...m/HEAD-a0dd663/share/nvim/runtime/lua/vim/treesitter.lua:239: in function 'fn'
    ...3/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:210: in function 'for_each_tree'
    ...m/HEAD-a0dd663/share/nvim/runtime/lua/vim/treesitter.lua:217: in function 'capture_fn'
    ...are/nvim/site/pack/packer/opt/neodim/lua/neodim/util.lua:27: in function 'get_treesitter_nodes'
    ...are/nvim/site/pack/packer/opt/neodim/lua/neodim/init.lua:22: in function 'get_ts_group'
    ...are/nvim/site/pack/packer/opt/neodim/lua/neodim/init.lua:49: in function 'get_hl'
    ...are/nvim/site/pack/packer/opt/neodim/lua/neodim/init.lua:55: in function 'create_diagnostic_extmark'
    ...are/nvim/site/pack/packer/opt/neodim/lua/neodim/init.lua:166: in function 'refresh'
    ...are/nvim/site/pack/packer/opt/neodim/lua/neodim/init.lua:200: in function 'hide'
    ...m/HEAD-a0dd663/share/nvim/runtime/lua/vim/diagnostic.lua:1112: in function 'hide'
    ...m/HEAD-a0dd663/share/nvim/runtime/lua/vim/diagnostic.lua:1470: in function 'reset'
    ...r/neovim/HEAD-a0dd663/share/nvim/runtime/lua/vim/lsp.lua:1146: in function <...r/neovim/HEAD-a0dd663/share/nvim/runtime/lua/vim/lsp.lua:1138>                                                                   

I will disable this plugin temporarily to see if it's the root of cause.

dsully commented 1 year ago

Just had it happen with sumneko_lua as well.

brianfabre commented 1 year ago

I've been having this exact issue as well

krehwell commented 1 year ago

for my case, this error happened when I'm using null-ls for my prettier formatting

zbirenbaum commented 1 year ago

I noticed just now as well that @dsully had update_in_insert set to false in his config. Do others having this issue use the same config param? If that isn't the problem I'm at a bit of a loss here, as looking through the functions called in the stack trace it shouldn't even be possible to trigger this.

I don't call match_preds directly, and the two places that do call it within query.lua both have checks to see if match (which is the argument referenced by the error message) is nil before making the call. My guess is that there may be some bug within vim.treesitter.get_captures_at_pos, or that a scheduled callback is running when it expects information that no longer exists due to the exit sequence. I think the callback situation is most likely, as pyright and null-ls are both very slow LSPs, although sumneko decidedly is not so that is quite strange. I also am fairly certain I perform my own checks to ensure that the information is still valid, but I'll double check them.

I was going to recommend trying a branch with the fallback function enabled, but it seems some api changes broke it for modern versions of neovim

itsdeadguy commented 1 year ago

Hello, i found this issue through web search. I am not a user of this plugin but i thought i'd chime in and say that i encounter this error every now and again as well, so clearly it's not something caused by neodim.

zbirenbaum commented 1 year ago

Hello, i found this issue through web search. I am not a user of this plugin but i thought i'd chime in and say that i encounter this error every now and again as well, so clearly it's not something caused by neodim.