|
@@ -4,6 +4,8 @@ local null_ls = require "null-ls"
|
|
local services = require "lvim.lsp.null-ls.services"
|
|
local services = require "lvim.lsp.null-ls.services"
|
|
local Log = require "lvim.core.log"
|
|
local Log = require "lvim.core.log"
|
|
|
|
|
|
|
|
+local is_registered = require("null-ls.sources").is_registered
|
|
|
|
+
|
|
function M.list_registered_providers(filetype)
|
|
function M.list_registered_providers(filetype)
|
|
local null_ls_methods = require "null-ls.methods"
|
|
local null_ls_methods = require "null-ls.methods"
|
|
local formatter_method = null_ls_methods.internal["FORMATTING"]
|
|
local formatter_method = null_ls_methods.internal["FORMATTING"]
|
|
@@ -30,24 +32,29 @@ function M.list_configured(formatter_configs)
|
|
local formatters, errors = {}, {}
|
|
local formatters, errors = {}, {}
|
|
|
|
|
|
for _, fmt_config in ipairs(formatter_configs) do
|
|
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
|
|
if not formatter then
|
|
Log:error("Not a valid formatter: " .. fmt_config.exe)
|
|
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
|
|
else
|
|
local formatter_cmd = services.find_command(formatter._opts.command)
|
|
local formatter_cmd = services.find_command(formatter._opts.command)
|
|
if not formatter_cmd then
|
|
if not formatter_cmd then
|
|
Log:warn("Not found: " .. formatter._opts.command)
|
|
Log:warn("Not found: " .. formatter._opts.command)
|
|
- errors[fmt_config.exe] = {} -- Add data here when necessary
|
|
|
|
|
|
+ errors[name] = {} -- Add data here when necessary
|
|
else
|
|
else
|
|
Log:debug("Using formatter: " .. formatter_cmd)
|
|
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
|
|
end
|
|
end
|
|
end
|
|
@@ -60,8 +67,8 @@ function M.setup(formatter_configs)
|
|
return
|
|
return
|
|
end
|
|
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
|
|
end
|
|
|
|
|
|
return M
|
|
return M
|