feat: support new null-ls (#1955)

This commit is contained in:
Christian Chiarulli 2021-11-16 14:55:45 +00:00 committed by GitHub
parent cad6355929
commit abc9f2764d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 48 additions and 30 deletions

View file

@ -4,6 +4,8 @@ local null_ls = require "null-ls"
local services = require "lvim.lsp.null-ls.services"
local Log = require "lvim.core.log"
local is_registered = require("null-ls.sources").is_registered
function M.list_registered_providers(filetype)
local null_ls_methods = require "null-ls.methods"
local formatter_method = null_ls_methods.internal["FORMATTING"]
@ -30,24 +32,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 +67,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