diff options
author | kylo252 <[email protected]> | 2022-01-06 11:37:49 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2022-01-06 11:37:49 +0100 |
commit | 8fd71b50847addb160d58c2045ced8d6f6c6e0ef (patch) | |
tree | ca565af19b46f0f0c1ffba391ac1393b2fb19c84 /lua/lvim/lsp/null-ls/code_actions.lua | |
parent | b10e18a213741dcd4ce1e7ba63accaf10719dbec (diff) |
refactor(null-ls): allow passing full list of options for sources (#2137)
Diffstat (limited to 'lua/lvim/lsp/null-ls/code_actions.lua')
-rw-r--r-- | lua/lvim/lsp/null-ls/code_actions.lua | 64 |
1 files changed, 9 insertions, 55 deletions
diff --git a/lua/lvim/lsp/null-ls/code_actions.lua b/lua/lvim/lsp/null-ls/code_actions.lua index bf6492b5..50f4cfb9 100644 --- a/lua/lvim/lsp/null-ls/code_actions.lua +++ b/lua/lvim/lsp/null-ls/code_actions.lua @@ -1,63 +1,14 @@ local M = {} -local null_ls = require "null-ls" -local services = require "lvim.lsp.null-ls.services" local Log = require "lvim.core.log" -local METHOD = null_ls.methods.CODE_ACTION - -local is_registered = function(name) - local query = { - name = name, - method = METHOD, - } - return require("null-ls.sources").is_registered(query) -end +local null_ls = require "null-ls" +local services = require "lvim.lsp.null-ls.services" +local method = null_ls.methods.CODE_ACTION function M.list_registered(filetype) local registered_providers = services.list_registered_providers_names(filetype) - return registered_providers[METHOD] or {} -end - -function M.list_configured(actions_configs) - local actors, errors = {}, {} - - for _, config in ipairs(actions_configs) do - vim.validate { - ["config.name"] = { config.name, "string" }, - } - - local name = config.name:gsub("-", "_") - local actor = null_ls.builtins.code_actions[name] - - if not actor then - Log:error("Not a valid code_actions: " .. config.name) - errors[name] = {} -- Add data here when necessary - elseif is_registered(config.name) then - Log:trace "Skipping registering the source more than once" - else - local command - if actor._opts.command then - command = services.find_command(actor._opts.command) - end - if not command and actor._opts.command ~= nil then - Log:warn("Not found: " .. actor._opts.command) - errors[name] = {} -- Add data here when necessary - else - Log:debug("Using code_actions: " .. (command or config.name)) - table.insert( - actors, - actor.with { - command = command, -- could be nil - extra_args = config.args, - filetypes = config.filetypes, - } - ) - end - end - end - - return { supported = actors, unsupported = errors } + return registered_providers[method] or {} end function M.setup(actions_configs) @@ -65,8 +16,11 @@ function M.setup(actions_configs) return end - local actions = M.list_configured(actions_configs) - null_ls.register { sources = actions.supported } + local registered = services.register_sources(actions_configs, method) + + if #registered > 0 then + Log:debug("Registered the following action-handlers: " .. unpack(registered)) + end end return M |