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 | |
parent | 611b15e94dadc7351d5ff67f268791d5269ea112 (diff) |
Merge updates from lunarvim
Diffstat (limited to '.config/nvim/lua/lsp/null-ls')
-rw-r--r-- | .config/nvim/lua/lsp/null-ls/formatters.lua | 19 | ||||
-rw-r--r-- | .config/nvim/lua/lsp/null-ls/init.lua | 16 | ||||
-rw-r--r-- | .config/nvim/lua/lsp/null-ls/linters.lua | 19 | ||||
-rw-r--r-- | .config/nvim/lua/lsp/null-ls/services.lua | 4 |
4 files changed, 37 insertions, 21 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 diff --git a/.config/nvim/lua/lsp/null-ls/init.lua b/.config/nvim/lua/lsp/null-ls/init.lua index 571fb6b..fde9fed 100644 --- a/.config/nvim/lua/lsp/null-ls/init.lua +++ b/.config/nvim/lua/lsp/null-ls/init.lua @@ -13,12 +13,18 @@ function M:setup() null_ls.config() require("lspconfig")["null-ls"].setup(options.lsp.null_ls.setup) - for _, filetype in pairs(options.lang) do - if filetype.formatters then - formatters.setup(filetype.formatters, filetype) + for filetype, config in pairs(options.lang) do + if not vim.tbl_isempty(config.formatters) then + vim.tbl_map(function(c) + c.filetypes = { filetype } + end, config.formatters) + formatters.setup(config.formatters) end - if filetype.linters then - linters.setup(filetype.linters, filetype) + if not vim.tbl_isempty(config.linters) then + vim.tbl_map(function(c) + c.filetypes = { filetype } + end, config.formatters) + linters.setup(config.linters) end end end 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 diff --git a/.config/nvim/lua/lsp/null-ls/services.lua b/.config/nvim/lua/lsp/null-ls/services.lua index c62fc70..ef9e7d2 100644 --- a/.config/nvim/lua/lsp/null-ls/services.lua +++ b/.config/nvim/lua/lsp/null-ls/services.lua @@ -4,8 +4,8 @@ local function find_root_dir() local util = require "lspconfig/util" local lsp_utils = require "lsp.utils" - local status_ok, ts_client = lsp_utils.is_client_active "typescript" - if status_ok then + local ts_client = lsp_utils.is_client_active "typescript" + if ts_client then return ts_client.config.root_dir end local dirname = vim.fn.expand "%:p:h" |