From df66b461596d351367f90d41a0fabffb873de4be Mon Sep 17 00:00:00 2001 From: Gustaf Rydholm Date: Mon, 11 Oct 2021 22:03:16 +0200 Subject: Merge updates from lunarvim --- .config/nvim/lua/lsp/null-ls/formatters.lua | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to '.config/nvim/lua/lsp/null-ls/formatters.lua') diff --git a/.config/nvim/lua/lsp/null-ls/formatters.lua b/.config/nvim/lua/lsp/null-ls/formatters.lua index 0d3505f..577a0d9 100644 --- a/.config/nvim/lua/lsp/null-ls/formatters.lua +++ b/.config/nvim/lua/lsp/null-ls/formatters.lua @@ -13,9 +13,13 @@ end function M.list_available(filetype) local formatters = {} + local tbl = require "utils.table" for _, provider in pairs(null_ls.builtins.formatting) do - -- TODO: Add support for wildcard filetypes - if vim.tbl_contains(provider.filetypes or {}, filetype) then + if + tbl.contains(provider.filetypes or {}, function(ft) + return ft == "*" or ft == filetype + end) + then table.insert(formatters, provider.name) end end @@ -27,7 +31,8 @@ function M.list_configured(formatter_configs) local formatters, errors = {}, {} for _, fmt_config in ipairs(formatter_configs) do - local formatter = null_ls.builtins.formatting[fmt_config.exe] + local formatter_name = fmt_config.exe:gsub("-", "_") + local formatter = null_ls.builtins.formatting[formatter_name] if not formatter then Log:error("Not a valid formatter: " .. fmt_config.exe) @@ -42,6 +47,7 @@ function M.list_configured(formatter_configs) formatters[fmt_config.exe] = formatter.with { command = formatter_cmd, extra_args = fmt_config.args, + filetypes = fmt_config.filetypes, } end end @@ -50,14 +56,13 @@ function M.list_configured(formatter_configs) return { supported = formatters, unsupported = errors } end -function M.setup(formatter_configs, filetype) +function M.setup(formatter_configs) if vim.tbl_isempty(formatter_configs) then return end - local formatters_by_ft = {} - formatters_by_ft[filetype] = M.list_configured(formatter_configs) - null_ls.register { sources = formatters_by_ft[filetype].supported } + local formatters_by_ft = M.list_configured(formatter_configs) + null_ls.register { sources = formatters_by_ft.supported } end return M -- cgit v1.2.3-70-g09d2