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/linters.lua | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to '.config/nvim/lua/lsp/null-ls/linters.lua') diff --git a/.config/nvim/lua/lsp/null-ls/linters.lua b/.config/nvim/lua/lsp/null-ls/linters.lua index e9e92e9..3f834ba 100644 --- a/.config/nvim/lua/lsp/null-ls/linters.lua +++ b/.config/nvim/lua/lsp/null-ls/linters.lua @@ -13,9 +13,13 @@ end function M.list_available(filetype) local linters = {} + local tbl = require "utils.table" for _, provider in pairs(null_ls.builtins.diagnostics) 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(linters, provider.name) end end @@ -27,7 +31,8 @@ function M.list_configured(linter_configs) local linters, errors = {}, {} for _, lnt_config in pairs(linter_configs) do - local linter = null_ls.builtins.diagnostics[lnt_config.exe] + local linter_name = lnt_config.exe:gsub("-", "_") + local linter = null_ls.builtins.diagnostics[linter_name] if not linter then Log:error("Not a valid linter: " .. lnt_config.exe) @@ -42,6 +47,7 @@ function M.list_configured(linter_configs) linters[lnt_config.exe] = linter.with { command = linter_cmd, extra_args = lnt_config.args, + filetypes = lnt_config.filetypes, } end end @@ -50,14 +56,13 @@ function M.list_configured(linter_configs) return { supported = linters, unsupported = errors } end -function M.setup(linter_configs, filetype) +function M.setup(linter_configs) if vim.tbl_isempty(linter_configs) then return end - local linters_by_ft = {} - linters_by_ft[filetype] = M.list_configured(linter_configs) - null_ls.register { sources = linters_by_ft[filetype].supported } + local linters = M.list_configured(linter_configs) + null_ls.register { sources = linters.supported } end return M -- cgit v1.2.3-70-g09d2