summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/lsp/null-ls
diff options
context:
space:
mode:
Diffstat (limited to '.config/nvim/lua/lsp/null-ls')
-rw-r--r--.config/nvim/lua/lsp/null-ls/formatters.lua38
-rw-r--r--.config/nvim/lua/lsp/null-ls/init.lua54
-rw-r--r--.config/nvim/lua/lsp/null-ls/linters.lua32
-rw-r--r--.config/nvim/lua/lsp/null-ls/services.lua16
4 files changed, 55 insertions, 85 deletions
diff --git a/.config/nvim/lua/lsp/null-ls/formatters.lua b/.config/nvim/lua/lsp/null-ls/formatters.lua
index 651d6f1..0d3505f 100644
--- a/.config/nvim/lua/lsp/null-ls/formatters.lua
+++ b/.config/nvim/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, option)
- option = option or {}
- local filter = option.filter or "supported"
-
- return vim.tbl_keys(formatters[filter])
-end
+local Log = require "core.log"
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)
@@ -45,15 +30,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,
@@ -65,12 +50,13 @@ function M.list_configured(formatter_configs)
return { supported = formatters, unsupported = errors }
end
-function M.setup(filetype, option)
- if not options.lang[filetype] or (formatters_by_ft[filetype] and not option.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(options.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/.config/nvim/lua/lsp/null-ls/init.lua b/.config/nvim/lua/lsp/null-ls/init.lua
index d12b40a..571fb6b 100644
--- a/.config/nvim/lua/lsp/null-ls/init.lua
+++ b/.config/nvim/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, option)
- option = option 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, option)
- linters.setup(filetype, option)
+ 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)
+ end
+ if filetype.linters then
+ linters.setup(filetype.linters, filetype)
+ end
+ end
end
return M
diff --git a/.config/nvim/lua/lsp/null-ls/linters.lua b/.config/nvim/lua/lsp/null-ls/linters.lua
index 0f6cbc1..e9e92e9 100644
--- a/.config/nvim/lua/lsp/null-ls/linters.lua
+++ b/.config/nvim/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, option)
- option = option or {}
- local filter = option.filter or "supported"
-
- return vim.tbl_keys(linters[filter])
-end
+local Log = require "core.log"
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)
@@ -65,12 +50,13 @@ function M.list_configured(linter_configs)
return { supported = linters, unsupported = errors }
end
-function M.setup(filetype, option)
- if not options.lang[filetype] or (linters_by_ft[filetype] and not option.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(options.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/.config/nvim/lua/lsp/null-ls/services.lua b/.config/nvim/lua/lsp/null-ls/services.lua
index a1e3a06..c62fc70 100644
--- a/.config/nvim/lua/lsp/null-ls/services.lua
+++ b/.config/nvim/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)
@@ -44,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