diff options
author | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2021-10-11 22:03:16 +0200 |
---|---|---|
committer | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2021-10-11 22:03:16 +0200 |
commit | df66b461596d351367f90d41a0fabffb873de4be (patch) | |
tree | 711b15790bb97ba0bfa57e1e863fe9a521d55bec /.config/nvim/lua/lsp/null-ls/formatters.lua | |
parent | 611b15e94dadc7351d5ff67f268791d5269ea112 (diff) |
Merge updates from lunarvim
Diffstat (limited to '.config/nvim/lua/lsp/null-ls/formatters.lua')
-rw-r--r-- | .config/nvim/lua/lsp/null-ls/formatters.lua | 19 |
1 files changed, 12 insertions, 7 deletions
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 |