kosayoda / nvim-lightbulb

VSCode 💡 for neovim's built-in LSP.
MIT License
783 stars 27 forks source link

Only invoke code action handler when code action method is supported #20

Closed petertriho closed 2 years ago

petertriho commented 2 years ago

It seems like this has broken the plugin for me https://github.com/neovim/neovim/pull/15926 Now getting the following error:

Error detected while processing CursorHold Autocommands for "<buffer=1>":
method textDocument/codeAction is not supported by any of the servers registered for the current buffer

I have tried adding the following into my on_attach function to guard against this

    if client.resolved_capabilities.code_action then
        vim.cmd([[
        augroup lsp_code_action
            autocmd! * <buffer>
            autocmd CursorHold,CursorHoldI <buffer> lua require('nvim-lightbulb').update_lightbulb()
        augroup END
        ]])
    end

But that doesn't help with something like null-ls where I believe code actions supported but (in my case) are only available for javascript/typescript files and errors with markdown files

EDIT: I also tried the standard config:

vim.cmd [[autocmd CursorHold,CursorHoldI * lua require'nvim-lightbulb'.update_lightbulb()]]

but get the same errors

kosayoda commented 2 years ago

@petertriho Please pull the latest master and let me know if it fixes your issue. If it doesn't (which it may not given your description of the null-ls setup, please provide a minimal configuration for me to reproduce on my machine.

petertriho commented 2 years ago

@kosayoda looks like that did the trick for any lsps with correctly reported resolved capabilities. For null-ls, it reports as supporting code actions despite me not having any enabled. I'll open an issue ticket there

wbthomason commented 2 years ago

@petertriho Did you find a fix without requesting changes from null-ls? I'm encountering this issue as well, and did not find a relevant issue report on the null-ls repo. If you're also still having this problem, I can open a ticket there.

petertriho commented 2 years ago

@wbthomason Not really fixes per se but my solution was to either register a code action source to null-ls (such as gitsigns) or in the on_attach I put

if client.name == "null-ls" then
   client.resolved_capabilities.code_action = false
end

But thanks for the reminder to open an issue ticket