Closed chrisgrieser closed 1 week ago
Hello! Does the action_kinds
option do what you want? Pasting the relevant docs here:
-- Code action kinds to observe.
-- To match all code actions, set to `nil`.
-- Otherwise, set to a table of kinds.
-- Example: { "quickfix", "refactor.rewrite" }
-- See: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#codeActionKind
action_kinds = nil,
Ah yes, that looks indeed looks je it could be it.
Do you know how I can tell which type a particular code action has?
Hello again. I just added a NvimLightbulb.debug()
function, can you let me know if this helps? Among other debug information it should show code actions at the location along with their type.
Example output:
hi, sorry for not responding. So yeah, it kinda goes in that direction. However, it would need to be quite fine-grained, since for example in one language, I Ignore refactors, in another language, I ignore quickfixes, etc.
Some sort of more general filter might be useful? Like I have this function which filters out code actions from vim.lsp.buf.code_action
I never use, and it would be great if the lightbulb could use such a filter function as well?
---@param action object CodeAction Obj https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#codeAction
---@return boolean
local function codeActionFilter(action)
local title, kind, ft = action.title, action.kind, vim.bo.ft
-- in lua, ignore all quickfixes except line disables and all rewrites
local ignoreInLua = ft == "lua"
and not (title:find("on this line"))
and (kind == "quickfix" or kind == "refactor.rewrite")
-- in python, ignore ruff actions except for line disables
local ignoreInPython = ft == "python"
and title:find("^Ruff")
and not (title:find("Disable for this line$"))
return not (ignoreInLua or ignoreInPython)
end
vim.keymap.set(
{ "n", "x" },
"<leader>c",
function() vim.lsp.buf.code_action { filter = codeActionFilter } end,
{ desc = "ó°’• Code Action" }
)
As said in https://github.com/kosayoda/nvim-lightbulb/issues/58#issuecomment-1870939846, allowing users to have a custom predicate or filter function fun(lsp.CodeAction|lsp.Command): boolean
would be a better and general enough solution.
Would it maybe be possible to ignore certain code actions? Like, some LSP servers have a bunch of useful code actions, but also a bunch of useless code actions, and the lightbulb appears for both.