2021-08-13 22:32:56 +02:00
|
|
|
local M = {}
|
|
|
|
|
2021-10-10 21:07:41 +02:00
|
|
|
local Log = require "lvim.core.log"
|
2021-08-13 22:32:56 +02:00
|
|
|
|
2022-01-06 11:37:49 +01:00
|
|
|
local null_ls = require "null-ls"
|
|
|
|
local services = require "lvim.lsp.null-ls.services"
|
|
|
|
local method = null_ls.methods.DIAGNOSTICS
|
2021-11-16 15:55:45 +01:00
|
|
|
|
2022-08-19 11:50:52 +02:00
|
|
|
local alternative_methods = {
|
|
|
|
null_ls.methods.DIAGNOSTICS,
|
|
|
|
null_ls.methods.DIAGNOSTICS_ON_OPEN,
|
|
|
|
null_ls.methods.DIAGNOSTICS_ON_SAVE,
|
|
|
|
}
|
|
|
|
|
2022-01-01 14:25:23 +01:00
|
|
|
function M.list_registered(filetype)
|
2021-10-03 16:13:46 +02:00
|
|
|
local registered_providers = services.list_registered_providers_names(filetype)
|
2022-08-19 11:50:52 +02:00
|
|
|
local providers_for_methods = vim.tbl_flatten(vim.tbl_map(function(m)
|
|
|
|
return registered_providers[m] or {}
|
|
|
|
end, alternative_methods))
|
|
|
|
|
|
|
|
return providers_for_methods
|
2021-08-13 22:32:56 +02:00
|
|
|
end
|
|
|
|
|
2022-01-01 14:25:23 +01:00
|
|
|
function M.list_supported(filetype)
|
|
|
|
local s = require "null-ls.sources"
|
|
|
|
local supported_linters = s.get_supported(filetype, "diagnostics")
|
|
|
|
table.sort(supported_linters)
|
|
|
|
return supported_linters
|
2021-08-13 22:32:56 +02:00
|
|
|
end
|
|
|
|
|
2021-10-09 13:39:15 +02:00
|
|
|
function M.setup(linter_configs)
|
2021-10-03 16:13:46 +02:00
|
|
|
if vim.tbl_isempty(linter_configs) then
|
2021-08-13 22:32:56 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2022-01-06 11:37:49 +01:00
|
|
|
local registered = services.register_sources(linter_configs, method)
|
|
|
|
|
|
|
|
if #registered > 0 then
|
|
|
|
Log:debug("Registered the following linters: " .. unpack(registered))
|
|
|
|
end
|
2021-08-13 22:32:56 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return M
|