From e9d8d8cd2ed24740ad881f74632feaafae83fe1d Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Wed, 1 Sep 2021 13:19:20 +0430 Subject: fix the string concat in logging (#1441) --- lua/lsp/null-ls/formatters.lua | 6 +++--- lua/lsp/null-ls/linters.lua | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'lua/lsp/null-ls') diff --git a/lua/lsp/null-ls/formatters.lua b/lua/lsp/null-ls/formatters.lua index 26be00da..2c2a4f06 100644 --- a/lua/lsp/null-ls/formatters.lua +++ b/lua/lsp/null-ls/formatters.lua @@ -45,15 +45,15 @@ function M.list_configured(formatter_configs) local formatter = null_ls.builtins.formatting[fmt_config.exe] if not formatter then - Log:error("Not a valid formatter:", fmt_config.exe) + Log:error("Not a valid formatter: " .. fmt_config.exe) errors[fmt_config.exe] = {} -- Add data here when necessary else local formatter_cmd = services.find_command(formatter._opts.command) if not formatter_cmd then - Log:warn("Not found:", formatter._opts.command) + Log:warn("Not found: " .. formatter._opts.command) errors[fmt_config.exe] = {} -- Add data here when necessary else - Log:debug("Using formatter:", formatter_cmd) + Log:debug("Using formatter: " .. formatter_cmd) formatters[fmt_config.exe] = formatter.with { command = formatter_cmd, extra_args = fmt_config.args } end end diff --git a/lua/lsp/null-ls/linters.lua b/lua/lsp/null-ls/linters.lua index bc191d7e..d88a8b83 100644 --- a/lua/lsp/null-ls/linters.lua +++ b/lua/lsp/null-ls/linters.lua @@ -45,15 +45,15 @@ function M.list_configured(linter_configs) local linter = null_ls.builtins.diagnostics[lnt_config.exe] if not linter then - Log:error("Not a valid linter:", lnt_config.exe) + Log:error("Not a valid linter: " .. lnt_config.exe) errors[lnt_config.exe] = {} -- Add data here when necessary else local linter_cmd = services.find_command(linter._opts.command) if not linter_cmd then - Log:warn("Not found:", linter._opts.command) + Log:warn("Not found: " .. linter._opts.command) errors[lnt_config.exe] = {} -- Add data here when necessary else - Log:debug("Using linter:", linter_cmd) + Log:debug("Using linter: " .. linter_cmd) linters[lnt_config.exe] = linter.with { command = linter_cmd, extra_args = lnt_config.args } end end -- cgit v1.2.3 From dbb958289b19f18739bc3d935e41e6c7ce75eab6 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Mon, 20 Sep 2021 14:15:22 +0430 Subject: add support for local stylelint (#1586) --- lua/lsp/null-ls/services.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'lua/lsp/null-ls') diff --git a/lua/lsp/null-ls/services.lua b/lua/lsp/null-ls/services.lua index a1e3a06c..1e76b40a 100644 --- a/lua/lsp/null-ls/services.lua +++ b/lua/lsp/null-ls/services.lua @@ -28,6 +28,7 @@ local local_providers = { prettier_d_slim = { find = from_node_modules }, eslint_d = { find = from_node_modules }, eslint = { find = from_node_modules }, + stylelint = { find = from_node_modules }, } function M.find_command(command) -- cgit v1.2.3 From d01ba08eaec1640ac2d038893525b3ba0af25813 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sun, 3 Oct 2021 16:13:46 +0200 Subject: refactor: auto-generate language configuration (#1584) Refactor the monolithic `lvim.lang` design into a more modular approach. IMPORTANT: run `:LvimUpdate` in order to generate the new ftplugin template files. --- lua/lsp/null-ls/formatters.lua | 30 +++++++---------------- lua/lsp/null-ls/init.lua | 54 ++++++++++++++---------------------------- lua/lsp/null-ls/linters.lua | 30 +++++++---------------- lua/lsp/null-ls/services.lua | 15 ++++++++++++ 4 files changed, 49 insertions(+), 80 deletions(-) (limited to 'lua/lsp/null-ls') diff --git a/lua/lsp/null-ls/formatters.lua b/lua/lsp/null-ls/formatters.lua index 2c2a4f06..8199aca0 100644 --- a/lua/lsp/null-ls/formatters.lua +++ b/lua/lsp/null-ls/formatters.lua @@ -1,29 +1,14 @@ local M = {} -local formatters_by_ft = {} local null_ls = require "null-ls" local services = require "lsp.null-ls.services" local Log = require "core.log" -local function list_names(formatters, options) - options = options or {} - local filter = options.filter or "supported" - - return vim.tbl_keys(formatters[filter]) -end - function M.list_supported_names(filetype) - if not formatters_by_ft[filetype] then - return {} - end - return list_names(formatters_by_ft[filetype], { filter = "supported" }) -end - -function M.list_unsupported_names(filetype) - if not formatters_by_ft[filetype] then - return {} - end - return list_names(formatters_by_ft[filetype], { filter = "unsupported" }) + local null_ls_methods = require "null-ls.methods" + local formatter_method = null_ls_methods.internal["FORMATTING"] + local registered_providers = services.list_registered_providers_names(filetype) + return registered_providers[formatter_method] or {} end function M.list_available(filetype) @@ -62,12 +47,13 @@ function M.list_configured(formatter_configs) return { supported = formatters, unsupported = errors } end -function M.setup(filetype, options) - if not lvim.lang[filetype] or (formatters_by_ft[filetype] and not options.force_reload) then +function M.setup(formatter_configs, filetype) + if vim.tbl_isempty(formatter_configs) then return end - formatters_by_ft[filetype] = M.list_configured(lvim.lang[filetype].formatters) + local formatters_by_ft = {} + formatters_by_ft[filetype] = M.list_configured(formatter_configs) null_ls.register { sources = formatters_by_ft[filetype].supported } end diff --git a/lua/lsp/null-ls/init.lua b/lua/lsp/null-ls/init.lua index ce4c07d9..0540fb48 100644 --- a/lua/lsp/null-ls/init.lua +++ b/lua/lsp/null-ls/init.lua @@ -1,44 +1,26 @@ local M = {} -function M.list_supported_provider_names(filetype) - local names = {} - - local formatters = require "lsp.null-ls.formatters" - local linters = require "lsp.null-ls.linters" - - vim.list_extend(names, formatters.list_supported_names(filetype)) - vim.list_extend(names, linters.list_supported_names(filetype)) - - return names -end - -function M.list_unsupported_provider_names(filetype) - local names = {} - - local formatters = require "lsp.null-ls.formatters" - local linters = require "lsp.null-ls.linters" - - vim.list_extend(names, formatters.list_unsupported_names(filetype)) - vim.list_extend(names, linters.list_unsupported_names(filetype)) - - return names -end - --- TODO: for linters and formatters with spaces and '-' replace with '_' -function M.setup(filetype, options) - options = options or {} - - local ok, _ = pcall(require, "null-ls") - if not ok then - require("core.log"):error "Missing null-ls dependency" +local Log = require "core.log" +local formatters = require "lsp.null-ls.formatters" +local linters = require "lsp.null-ls.linters" + +function M:setup() + local status_ok, null_ls = pcall(require, "null-ls") + if not status_ok then + Log:error "Missing null-ls dependency" return end - local formatters = require "lsp.null-ls.formatters" - local linters = require "lsp.null-ls.linters" - - formatters.setup(filetype, options) - linters.setup(filetype, options) + null_ls.config() + require("lspconfig")["null-ls"].setup {} + for _, filetype in pairs(lvim.lang) do + if filetype.formatters then + formatters.setup(filetype.formatters, filetype) + end + if filetype.linters then + linters.setup(filetype.linters, filetype) + end + end end return M diff --git a/lua/lsp/null-ls/linters.lua b/lua/lsp/null-ls/linters.lua index d88a8b83..ea45fa87 100644 --- a/lua/lsp/null-ls/linters.lua +++ b/lua/lsp/null-ls/linters.lua @@ -1,29 +1,14 @@ local M = {} -local linters_by_ft = {} local null_ls = require "null-ls" local services = require "lsp.null-ls.services" local Log = require "core.log" -local function list_names(linters, options) - options = options or {} - local filter = options.filter or "supported" - - return vim.tbl_keys(linters[filter]) -end - function M.list_supported_names(filetype) - if not linters_by_ft[filetype] then - return {} - end - return list_names(linters_by_ft[filetype], { filter = "supported" }) -end - -function M.list_unsupported_names(filetype) - if not linters_by_ft[filetype] then - return {} - end - return list_names(linters_by_ft[filetype], { filter = "unsupported" }) + local null_ls_methods = require "null-ls.methods" + local linter_method = null_ls_methods.internal["DIAGNOSTICS"] + local registered_providers = services.list_registered_providers_names(filetype) + return registered_providers[linter_method] or {} end function M.list_available(filetype) @@ -62,12 +47,13 @@ function M.list_configured(linter_configs) return { supported = linters, unsupported = errors } end -function M.setup(filetype, options) - if not lvim.lang[filetype] or (linters_by_ft[filetype] and not options.force_reload) then +function M.setup(linter_configs, filetype) + if vim.tbl_isempty(linter_configs) then return end - linters_by_ft[filetype] = M.list_configured(lvim.lang[filetype].linters) + local linters_by_ft = {} + linters_by_ft[filetype] = M.list_configured(linter_configs) null_ls.register { sources = linters_by_ft[filetype].supported } end diff --git a/lua/lsp/null-ls/services.lua b/lua/lsp/null-ls/services.lua index 1e76b40a..c62fc709 100644 --- a/lua/lsp/null-ls/services.lua +++ b/lua/lsp/null-ls/services.lua @@ -45,4 +45,19 @@ function M.find_command(command) return nil end +function M.list_registered_providers_names(filetype) + local u = require "null-ls.utils" + local c = require "null-ls.config" + local registered = {} + for method, source in pairs(c.get()._methods) do + for name, filetypes in pairs(source) do + if u.filetype_matches(filetypes, filetype) then + registered[method] = registered[method] or {} + table.insert(registered[method], name) + end + end + end + return registered +end + return M -- cgit v1.2.3 From 76bee64f17cb7e7db33ee61645088d2b0729eb09 Mon Sep 17 00:00:00 2001 From: dklymenk <64093836+dklymenk@users.noreply.github.com> Date: Tue, 5 Oct 2021 00:09:40 +0300 Subject: fix: return null ls setup user config (#1683) --- lua/lsp/null-ls/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lua/lsp/null-ls') diff --git a/lua/lsp/null-ls/init.lua b/lua/lsp/null-ls/init.lua index 0540fb48..1d0af77b 100644 --- a/lua/lsp/null-ls/init.lua +++ b/lua/lsp/null-ls/init.lua @@ -12,7 +12,7 @@ function M:setup() end null_ls.config() - require("lspconfig")["null-ls"].setup {} + require("lspconfig")["null-ls"].setup(lvim.lsp.null_ls.setup) for _, filetype in pairs(lvim.lang) do if filetype.formatters then formatters.setup(filetype.formatters, filetype) -- cgit v1.2.3 From f4899e316516fc6fc544b148cb7e9a04fbda130e Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Fri, 8 Oct 2021 08:57:11 +0200 Subject: fix: register null-ls providers per filetype (#1709) --- lua/lsp/null-ls/formatters.lua | 13 ++++++++----- lua/lsp/null-ls/init.lua | 10 +++++----- lua/lsp/null-ls/linters.lua | 13 ++++++++----- 3 files changed, 21 insertions(+), 15 deletions(-) (limited to 'lua/lsp/null-ls') diff --git a/lua/lsp/null-ls/formatters.lua b/lua/lsp/null-ls/formatters.lua index 8199aca0..636b0bde 100644 --- a/lua/lsp/null-ls/formatters.lua +++ b/lua/lsp/null-ls/formatters.lua @@ -23,7 +23,7 @@ function M.list_available(filetype) return formatters end -function M.list_configured(formatter_configs) +function M.list_configured(formatter_configs, filetype) local formatters, errors = {}, {} for _, fmt_config in ipairs(formatter_configs) do @@ -39,7 +39,11 @@ function M.list_configured(formatter_configs) errors[fmt_config.exe] = {} -- 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 } + formatters[fmt_config.exe] = formatter.with { + command = formatter_cmd, + extra_args = fmt_config.args, + filetypes = { filetype }, + } end end end @@ -52,9 +56,8 @@ function M.setup(formatter_configs, filetype) 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, filetype) + null_ls.register { sources = formatters_by_ft.supported } end return M diff --git a/lua/lsp/null-ls/init.lua b/lua/lsp/null-ls/init.lua index 1d0af77b..3c8909af 100644 --- a/lua/lsp/null-ls/init.lua +++ b/lua/lsp/null-ls/init.lua @@ -13,12 +13,12 @@ function M:setup() null_ls.config() require("lspconfig")["null-ls"].setup(lvim.lsp.null_ls.setup) - for _, filetype in pairs(lvim.lang) do - if filetype.formatters then - formatters.setup(filetype.formatters, filetype) + for filetype, config in pairs(lvim.lang) do + if not vim.tbl_isempty(config.formatters) then + formatters.setup(config.formatters, filetype) end - if filetype.linters then - linters.setup(filetype.linters, filetype) + if not vim.tbl_isempty(config.linters) then + linters.setup(config.linters, filetype) end end end diff --git a/lua/lsp/null-ls/linters.lua b/lua/lsp/null-ls/linters.lua index ea45fa87..34a78a65 100644 --- a/lua/lsp/null-ls/linters.lua +++ b/lua/lsp/null-ls/linters.lua @@ -23,7 +23,7 @@ function M.list_available(filetype) return linters end -function M.list_configured(linter_configs) +function M.list_configured(linter_configs, filetype) local linters, errors = {}, {} for _, lnt_config in pairs(linter_configs) do @@ -39,7 +39,11 @@ function M.list_configured(linter_configs) errors[lnt_config.exe] = {} -- Add data here when necessary else Log:debug("Using linter: " .. linter_cmd) - linters[lnt_config.exe] = linter.with { command = linter_cmd, extra_args = lnt_config.args } + linters[lnt_config.exe] = linter.with { + command = linter_cmd, + extra_args = lnt_config.args, + filetypes = { filetype }, + } end end end @@ -52,9 +56,8 @@ function M.setup(linter_configs, filetype) 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_by_ft = M.list_configured(linter_configs, filetype) + null_ls.register { sources = linters_by_ft.supported } end return M -- cgit v1.2.3 From efd82c87568a791b2f7fb9c94b763f2c1950dc8e Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sat, 9 Oct 2021 13:39:15 +0200 Subject: feat: configure multiple filetypes per provider (#1725) --- lua/lsp/null-ls/formatters.lua | 8 ++++---- lua/lsp/null-ls/init.lua | 10 ++++++++-- lua/lsp/null-ls/linters.lua | 10 +++++----- 3 files changed, 17 insertions(+), 11 deletions(-) (limited to 'lua/lsp/null-ls') diff --git a/lua/lsp/null-ls/formatters.lua b/lua/lsp/null-ls/formatters.lua index 636b0bde..d6455d5f 100644 --- a/lua/lsp/null-ls/formatters.lua +++ b/lua/lsp/null-ls/formatters.lua @@ -23,7 +23,7 @@ function M.list_available(filetype) return formatters end -function M.list_configured(formatter_configs, filetype) +function M.list_configured(formatter_configs) local formatters, errors = {}, {} for _, fmt_config in ipairs(formatter_configs) do @@ -42,7 +42,7 @@ function M.list_configured(formatter_configs, filetype) formatters[fmt_config.exe] = formatter.with { command = formatter_cmd, extra_args = fmt_config.args, - filetypes = { filetype }, + filetypes = fmt_config.filetypes, } end end @@ -51,12 +51,12 @@ function M.list_configured(formatter_configs, filetype) 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 = M.list_configured(formatter_configs, filetype) + local formatters_by_ft = M.list_configured(formatter_configs) null_ls.register { sources = formatters_by_ft.supported } end diff --git a/lua/lsp/null-ls/init.lua b/lua/lsp/null-ls/init.lua index 3c8909af..0d030c22 100644 --- a/lua/lsp/null-ls/init.lua +++ b/lua/lsp/null-ls/init.lua @@ -15,10 +15,16 @@ function M:setup() require("lspconfig")["null-ls"].setup(lvim.lsp.null_ls.setup) for filetype, config in pairs(lvim.lang) do if not vim.tbl_isempty(config.formatters) then - formatters.setup(config.formatters, filetype) + vim.tbl_map(function(c) + c.filetypes = { filetype } + end, config.formatters) + formatters.setup(config.formatters) end if not vim.tbl_isempty(config.linters) then - linters.setup(config.linters, filetype) + vim.tbl_map(function(c) + c.filetypes = { filetype } + end, config.formatters) + linters.setup(config.linters) end end end diff --git a/lua/lsp/null-ls/linters.lua b/lua/lsp/null-ls/linters.lua index 34a78a65..e60411e6 100644 --- a/lua/lsp/null-ls/linters.lua +++ b/lua/lsp/null-ls/linters.lua @@ -23,7 +23,7 @@ function M.list_available(filetype) return linters end -function M.list_configured(linter_configs, filetype) +function M.list_configured(linter_configs) local linters, errors = {}, {} for _, lnt_config in pairs(linter_configs) do @@ -42,7 +42,7 @@ function M.list_configured(linter_configs, filetype) linters[lnt_config.exe] = linter.with { command = linter_cmd, extra_args = lnt_config.args, - filetypes = { filetype }, + filetypes = lnt_config.filetypes, } end end @@ -51,13 +51,13 @@ function M.list_configured(linter_configs, filetype) 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 = M.list_configured(linter_configs, filetype) - null_ls.register { sources = linters_by_ft.supported } + local linters = M.list_configured(linter_configs) + null_ls.register { sources = linters.supported } end return M -- cgit v1.2.3 From b524100f016de6b934894547d48f9ef811902397 Mon Sep 17 00:00:00 2001 From: Luc Sinet Date: Sat, 9 Oct 2021 13:45:34 +0200 Subject: feat: support wildcard filetypes for null-ls providers (#1447) Co-authored-by: kylo252 <59826753+kylo252@users.noreply.github.com> --- lua/lsp/null-ls/formatters.lua | 9 ++++++--- lua/lsp/null-ls/linters.lua | 9 ++++++--- lua/lsp/null-ls/services.lua | 4 ++-- 3 files changed, 14 insertions(+), 8 deletions(-) (limited to 'lua/lsp/null-ls') diff --git a/lua/lsp/null-ls/formatters.lua b/lua/lsp/null-ls/formatters.lua index d6455d5f..4728b908 100644 --- a/lua/lsp/null-ls/formatters.lua +++ b/lua/lsp/null-ls/formatters.lua @@ -13,9 +13,11 @@ 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 +29,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) diff --git a/lua/lsp/null-ls/linters.lua b/lua/lsp/null-ls/linters.lua index e60411e6..549c6cdd 100644 --- a/lua/lsp/null-ls/linters.lua +++ b/lua/lsp/null-ls/linters.lua @@ -13,9 +13,11 @@ 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 +29,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) diff --git a/lua/lsp/null-ls/services.lua b/lua/lsp/null-ls/services.lua index c62fc709..ef9e7d22 100644 --- a/lua/lsp/null-ls/services.lua +++ b/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" -- cgit v1.2.3