diff options
author | kylo252 <[email protected]> | 2021-12-13 17:58:35 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-12-13 17:58:35 +0100 |
commit | 6cf21e9ddec41addf01744176afb2e138b3e1b3f (patch) | |
tree | 4abf843da0e2ed38689c872694b13d7418536106 /lua/lvim/lsp/null-ls | |
parent | 3a2d62ed2510ca05eb6ea87240a86df82338f5aa (diff) | |
parent | b09ada89402e668ea1636bdbf671a89330199717 (diff) |
Merge LunarVim/release-candidate
Diffstat (limited to 'lua/lvim/lsp/null-ls')
-rw-r--r-- | lua/lvim/lsp/null-ls/code_actions.lua | 81 | ||||
-rw-r--r-- | lua/lvim/lsp/null-ls/formatters.lua | 35 | ||||
-rw-r--r-- | lua/lvim/lsp/null-ls/init.lua | 2 | ||||
-rw-r--r-- | lua/lvim/lsp/null-ls/linters.lua | 30 | ||||
-rw-r--r-- | lua/lvim/lsp/null-ls/services.lua | 14 |
5 files changed, 134 insertions, 28 deletions
diff --git a/lua/lvim/lsp/null-ls/code_actions.lua b/lua/lvim/lsp/null-ls/code_actions.lua new file mode 100644 index 00000000..ff59fabf --- /dev/null +++ b/lua/lvim/lsp/null-ls/code_actions.lua @@ -0,0 +1,81 @@ +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 + +function M.list_registered_providers(filetype) + local registered_providers = services.list_registered_providers_names(filetype) + return registered_providers[METHOD] or {} +end + +function M.list_available(filetype) + local availables = require("null-ls.sources").get_available(filetype, METHOD) + local actors = vim.tbl_map(function(src) + return src.name + end, availables) + table.sort(actors) + return actors +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 } +end + +function M.setup(actions_configs) + if vim.tbl_isempty(actions_configs) then + return + end + + local actions = M.list_configured(actions_configs) + null_ls.register { sources = actions.supported } +end + +return M diff --git a/lua/lvim/lsp/null-ls/formatters.lua b/lua/lvim/lsp/null-ls/formatters.lua index 20939039..b2e191c5 100644 --- a/lua/lvim/lsp/null-ls/formatters.lua +++ b/lua/lvim/lsp/null-ls/formatters.lua @@ -4,6 +4,14 @@ local null_ls = require "null-ls" local services = require "lvim.lsp.null-ls.services" local Log = require "lvim.core.log" +local is_registered = function(name) + local query = { + name = name, + method = require("null-ls").methods.FORMATTING, + } + return require("null-ls.sources").is_registered(query) +end + function M.list_registered_providers(filetype) local null_ls_methods = require "null-ls.methods" local formatter_method = null_ls_methods.internal["FORMATTING"] @@ -30,24 +38,29 @@ function M.list_configured(formatter_configs) local formatters, errors = {}, {} for _, fmt_config in ipairs(formatter_configs) do - local formatter_name = fmt_config.exe:gsub("-", "_") - local formatter = null_ls.builtins.formatting[formatter_name] + local name = fmt_config.exe:gsub("-", "_") + local formatter = null_ls.builtins.formatting[name] if not formatter then Log:error("Not a valid formatter: " .. fmt_config.exe) - errors[fmt_config.exe] = {} -- Add data here when necessary + errors[name] = {} -- Add data here when necessary + elseif is_registered(fmt_config.exe) then + Log:trace "Skipping registering the source more than once" else local formatter_cmd = services.find_command(formatter._opts.command) if not formatter_cmd then Log:warn("Not found: " .. formatter._opts.command) - errors[fmt_config.exe] = {} -- Add data here when necessary + errors[name] = {} -- Add data here when necessary else Log:debug("Using formatter: " .. formatter_cmd) - formatters[fmt_config.exe] = formatter.with { - command = formatter_cmd, - extra_args = fmt_config.args, - filetypes = fmt_config.filetypes, - } + table.insert( + formatters, + formatter.with { + command = formatter_cmd, + extra_args = fmt_config.args, + filetypes = fmt_config.filetypes, + } + ) end end end @@ -60,8 +73,8 @@ function M.setup(formatter_configs) return end - local formatters_by_ft = M.list_configured(formatter_configs) - null_ls.register { sources = formatters_by_ft.supported } + local formatters = M.list_configured(formatter_configs) + null_ls.register { sources = formatters.supported } end return M diff --git a/lua/lvim/lsp/null-ls/init.lua b/lua/lvim/lsp/null-ls/init.lua index 5e8c6b11..f5e820e8 100644 --- a/lua/lvim/lsp/null-ls/init.lua +++ b/lua/lvim/lsp/null-ls/init.lua @@ -9,7 +9,7 @@ function M:setup() return end - null_ls.config() + null_ls.config(lvim.lsp.null_ls.config) local default_opts = require("lvim.lsp").get_common_opts() if vim.tbl_isempty(lvim.lsp.null_ls.setup or {}) then diff --git a/lua/lvim/lsp/null-ls/linters.lua b/lua/lvim/lsp/null-ls/linters.lua index ced4bf34..6a793d26 100644 --- a/lua/lvim/lsp/null-ls/linters.lua +++ b/lua/lvim/lsp/null-ls/linters.lua @@ -4,6 +4,14 @@ local null_ls = require "null-ls" local services = require "lvim.lsp.null-ls.services" local Log = require "lvim.core.log" +local is_registered = function(name) + local query = { + name = name, + method = require("null-ls").methods.DIAGNOSTICS, + } + return require("null-ls.sources").is_registered(query) +end + function M.list_registered_providers(filetype) local null_ls_methods = require "null-ls.methods" local linter_method = null_ls_methods.internal["DIAGNOSTICS"] @@ -21,6 +29,7 @@ function M.list_available(filetype) table.insert(linters, provider.name) end end + table.sort(linters) return linters end @@ -29,24 +38,29 @@ function M.list_configured(linter_configs) local linters, errors = {}, {} for _, lnt_config in pairs(linter_configs) do - local linter_name = lnt_config.exe:gsub("-", "_") - local linter = null_ls.builtins.diagnostics[linter_name] + local name = lnt_config.exe:gsub("-", "_") + local linter = null_ls.builtins.diagnostics[name] if not linter then Log:error("Not a valid linter: " .. lnt_config.exe) errors[lnt_config.exe] = {} -- Add data here when necessary + elseif is_registered(lnt_config.exe) then + Log:trace "Skipping registering the source more than once" else local linter_cmd = services.find_command(linter._opts.command) if not linter_cmd then Log:warn("Not found: " .. linter._opts.command) - errors[lnt_config.exe] = {} -- Add data here when necessary + errors[name] = {} -- Add data here when necessary else Log:debug("Using linter: " .. linter_cmd) - linters[lnt_config.exe] = linter.with { - command = linter_cmd, - extra_args = lnt_config.args, - filetypes = lnt_config.filetypes, - } + table.insert( + linters, + linter.with { + command = linter_cmd, + extra_args = lnt_config.args, + filetypes = lnt_config.filetypes, + } + ) end end end diff --git a/lua/lvim/lsp/null-ls/services.lua b/lua/lvim/lsp/null-ls/services.lua index 9cb29f49..9151cc39 100644 --- a/lua/lvim/lsp/null-ls/services.lua +++ b/lua/lvim/lsp/null-ls/services.lua @@ -46,15 +46,13 @@ function M.find_command(command) end function M.list_registered_providers_names(filetype) - local u = require "null-ls.utils" - local c = require "null-ls.config" + local s = require "null-ls.sources" + local available_sources = s.get_available(filetype) local registered = {} - for method, source in pairs(c.get()._methods) do - for name, filetypes in pairs(source) do - if u.filetype_matches(filetypes, filetype) then - registered[method] = registered[method] or {} - table.insert(registered[method], name) - end + for _, source in ipairs(available_sources) do + for method in pairs(source.methods) do + registered[method] = registered[method] or {} + table.insert(registered[method], source.name) end end return registered |