elixir-tools / elixir-tools.nvim

Neovim plugin for Elixir
MIT License
417 stars 31 forks source link

Error with codelen config: `Invalid buffer id` #56

Closed SichangHe closed 1 year ago

SichangHe commented 1 year ago

Please see this issue I posted in glepnir/lspsaga.nvim.

Copied here:

Describe the bug

Moving down in the window opened by :Lspsaga outline throws errors:

   Error  10:36:25 msg_show.lua_error Error executing vim.schedule lua callback: ...neovim/0.8.2/share/nvim/runtime/lua/vim/lsp/codelens.lua:166: Invalid buffer id: <BUFFER_ID>
stack traceback:
  [C]: in function 'nvim_buf_attach'
  ...neovim/0.8.2/share/nvim/runtime/lua/vim/lsp/codelens.lua:166: in function 'save'
  ...neovim/0.8.2/share/nvim/runtime/lua/vim/lsp/codelens.lua:229: in function 'handler'
  ...w/Cellar/neovim/0.8.2/share/nvim/runtime/lua/vim/lsp.lua:1383: in function ''
  vim/_editor.lua: in function <vim/_editor.lua:0>

Steps to reproduce

Using this init.lua:

require('packer').startup(function(use)
    use {
        'glepnir/lspsaga.nvim',
        event = 'VimEnter',
        requires = { 'nvim-tree/nvim-web-devicons' },
        config = function()
            require('lspsaga').setup {
                lightbulb = {
                    enable_in_insert = false,
                    virtual_text = false,
                },
                symbol_in_winbar = {
                    enable = false,
                },
                ui = {
                    border = 'none',
                },
            }
        end,
    }

    use {
        'mhanberg/elixir.nvim',
        ft = { 'elixir' },
        config = function()
            local ex = require('elixir')
            ex.setup {
                cmd = 'elixir-ls',
                settings = ex.settings {
                    enableTestLenses = true,
                    suggestSpecs = true,
                },
            }
        end
    }
end)

(I suspect that it does not have to be an Elixir LS, but any LS.)

Open up a new Neovim session and :PackerCompile.

Reopen Neovim in a project so that the buffer has LSP attached. It seems that the buffer needs to have functions.

Run :Lspsaga outline.

Press down j for a little while.

See demo video below: demo video

Expected behavior

No error should occur.

Also, the floating window should be above the outline window, but that is another bug.

Neovim version (nvim -v)

NVIM v0.8.2

lspsaga commit

54725e8

Terminal name/version

alacritty 0.11.0 (8dbaa0b)

SichangHe commented 1 year ago

I have jumped through hoops to confirm that this issue is indeed with elixir.nvim.

The following init.lua does not give me the error:

require('packer').startup(function(use)
    use {
        'glepnir/lspsaga.nvim',
        event = 'VimEnter',
        requires = { 'nvim-tree/nvim-web-devicons' },
        config = function()
            require('lspsaga').setup {
                lightbulb = {
                    enable_in_insert = false,
                    virtual_text = false,
                },
                symbol_in_winbar = {
                    enable = false,
                },
                ui = {
                    border = 'none',
                },
            }
        end,
    }

    use {
        'williamboman/mason.nvim',
        config = function()
            require('mason').setup {}
        end,
    }

    use {
        'williamboman/mason-lspconfig.nvim',
        requires = {
            'williamboman/mason.nvim',
            'neovim/nvim-lspconfig',
        },
        config = function()
            local servers = {
                sumneko_lua = {},
            }
            require('mason-lspconfig').setup_handlers {
                function(name)
                    if servers[name] then
                        require('lspconfig')[name].setup {
                            settings = servers[name],
                        }
                    end
                end
            }
        end,
    }
end)
mhanberg commented 1 year ago

Hi @SichangHe!

Are you able to reproduce this with elixir.nvim and not including lspsaga? I don't think showing the absence of an error with another LSP/plug proves the presence of a bug in elixir.nvim.

lessthanseventy commented 1 year ago

I have been seeing the same thing, and I was able to confirm the bug lies in elixir-tools.nvim. I initially suspected my file explorer plugin oil.nvim. I would see this error when leaving a floating oil window. After landing here, removing plugins and trying different combinations, I only saw the bug when elixir-tools.nvim was present.

When I remove these lines pertaining to the codelens support, I no longer see the same error.

mhanberg commented 1 year ago

This might be related https://github.com/neovim/neovim/pull/23894/files

lessthanseventy commented 1 year ago

I'll keep an eye on it and see if that fixes it. I suspect you are correct.

mhanberg commented 1 year ago

I am rather convinced this is just a neovim codelens issue and not an elixir-tools.nvim issue, so i will close this ticket.

if that ends up not being the case, please let me know.