diff options
Diffstat (limited to '.config/nvim/lua/lsp/null-ls/formatters.lua')
-rw-r--r-- | .config/nvim/lua/lsp/null-ls/formatters.lua | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/.config/nvim/lua/lsp/null-ls/formatters.lua b/.config/nvim/lua/lsp/null-ls/formatters.lua index 991f613..7bd4dc4 100644 --- a/.config/nvim/lua/lsp/null-ls/formatters.lua +++ b/.config/nvim/lua/lsp/null-ls/formatters.lua @@ -4,6 +4,8 @@ local null_ls = require "null-ls" local services = require "lsp.null-ls.services" local Log = require "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"] @@ -32,24 +34,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 @@ -62,8 +69,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 |