kosayoda / nvim-lightbulb

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

Certain servers return code actions without kinds #54

Open kosayoda opened 1 year ago

kosayoda commented 1 year ago
Error executing vim.schedule lua callback: ...are/nvim/lazy/nvim-lightbulb/lua/nvim-lightbulb/init.lua:405: attempt to concatenate field 'kind' (a nil value)
stack traceback:
    ...are/nvim/lazy/nvim-lightbulb/lua/nvim-lightbulb/init.lua:405: in function 'callback'
    ...eovim-unwrapped-0.9.1/share/nvim/runtime/lua/vim/lsp.lua:2021: in function 'handler'
    ...eovim-unwrapped-0.9.1/share/nvim/runtime/lua/vim/lsp.lua:1394: in function ''
    vim/_editor.lua: in function <vim/_editor.lua:0>

I'm getting this in Cargo.toml with crates.nvim plugin. I would personally prefer if the kind is unknown, then the lightbulb still be hidden, because right now, it is showing on every line.

Originally posted by @utkarshgupta137 in https://github.com/kosayoda/nvim-lightbulb/issues/47#issuecomment-1644504678

kosayoda commented 1 year ago

I've fixed the concatenation bug in https://github.com/kosayoda/nvim-lightbulb/commit/8f00b89dd1b1dbde16872bee5fbcee2e58c9b8e9.

In that commit I've also added a new config option: ignore.actions_without_kind that would allow ignoring code actions that do not have or have an empty string for the kind.

@utkarshgupta137 I tested the option with null-ls and crates.nvim and it seems to work as expected. Let me know here if it does for you too. Alternatively, you can blanket turn off the lightbulb for null-ls by adding it to ignore.clients.

utkarshgupta137 commented 1 year ago

Working for crates.nvim. But I noticed that it isn't working for marksman:

11:27:23 msg_show.echomsg   NvimLightbulb.debug({ action_kinds = { "quickfix" } }) [Configuration]
{
  sign = { hl = 'LightBulbSign', text = '💡', enabled = true },
  line = { hl = 'LightBulbLine', enabled = false },
  float = {
    hl = 'LightBulbFloatWin',
    text = '💡',
    win_opts = { focusable = false },
    enabled = false
  },
  ignore_id = {},
  priority = 100,
  autocmd = {
    enabled = true,
    events = { 'CursorHold', 'CursorHoldI' },
    pattern = { '*' },
    updatetime = 200
  },
  status_text = { text = '💡', text_unavailable = '', enabled = false },
  ignore = { clients = {}, actions_without_kind = true, ft = {} },
  number = { hl = 'LightBulbNumber', enabled = false },
  link_highlights = true,
  hide_in_unfocused_buffer = true,
  action_kinds = { 'quickfix' },
  validate_config = 'auto',
  virtual_text = {
    enabled = false,
    hl = 'LightBulbVirtualText',
    hl_mode = 'combine',
    text = '💡',
    pos = 'eol'
  }
}

[Code Actions]
i   No code action support: null-ls, copilot
i With code action support: marksman

marksman
1. Create a Table of Contents source

Any ideas? Or do I just need to disable the client?

utkarshgupta137 commented 1 year ago

Here's my config: https://github.com/utkarshgupta137/nvim-lazy/commit/1753b4ba103cf87121678badd4891531e0787b95

kosayoda commented 1 year ago

TLDR:

So marksman actually provides a kind for their code actions, in the Create a Table of Contents situation it's source. For now I recommend ignoring the marksman client.

Details:

The way action_kinds work currently is by sending the whitelist to the server during the code action request:

image

Unfortunately as you can see it's

So servers can omit computing them

and not

So servers must omit computing them

The docs also say that "...are filtered out by the client" before being shown so technically that's on me, but I don't want to have to examine every code action and match the kind against every kind in the whitelist. If we were to want to filter out eg based on name too then there would be an explosion in cases to handle.

So, I am thinking of allowing the user to provide custom lua function with a specific signature that will allow the user to receive the action information and return whether or not to ignore it. What do you think?

Thanks for being patient!

utkarshgupta137 commented 1 year ago

Disabling marksman works for me. Thanks for your support!