feat: support new null-ls (#1955)

This commit is contained in:
Christian Chiarulli 2021-11-16 14:55:45 +00:00 committed by GitHub
parent cad6355929
commit abc9f2764d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 48 additions and 30 deletions

View file

@ -20,6 +20,7 @@ end
local function make_formatters_info(ft)
local null_formatters = require "lvim.lsp.null-ls.formatters"
local registered_formatters = null_formatters.list_registered_providers(ft)
-- print("reg", vim.inspect(registered_formatters))
local supported_formatters = null_formatters.list_available(ft)
local section = {
"Formatters info",

View file

@ -40,6 +40,7 @@ return {
},
null_ls = {
setup = {},
config = {},
},
override = {
"angularls",

View file

@ -4,6 +4,8 @@ local null_ls = require "null-ls"
local services = require "lvim.lsp.null-ls.services"
local Log = require "lvim.core.log"
local is_registered = require("null-ls.sources").is_registered
function M.list_registered_providers(filetype)
local null_ls_methods = require "null-ls.methods"
local formatter_method = null_ls_methods.internal["FORMATTING"]
@ -30,24 +32,29 @@ function M.list_configured(formatter_configs)
local formatters, errors = {}, {}
for _, fmt_config in ipairs(formatter_configs) do
local formatter_name = fmt_config.exe:gsub("-", "_")
local formatter = null_ls.builtins.formatting[formatter_name]
local name = fmt_config.exe:gsub("-", "_")
local formatter = null_ls.builtins.formatting[name]
if not formatter then
Log:error("Not a valid formatter: " .. fmt_config.exe)
errors[fmt_config.exe] = {} -- Add data here when necessary
errors[name] = {} -- Add data here when necessary
elseif is_registered(fmt_config.exe) then
Log:trace "Skipping registering the source more than once"
else
local formatter_cmd = services.find_command(formatter._opts.command)
if not formatter_cmd then
Log:warn("Not found: " .. formatter._opts.command)
errors[fmt_config.exe] = {} -- Add data here when necessary
errors[name] = {} -- 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,
filetypes = fmt_config.filetypes,
}
table.insert(
formatters,
formatter.with {
command = formatter_cmd,
extra_args = fmt_config.args,
filetypes = fmt_config.filetypes,
}
)
end
end
end
@ -60,8 +67,8 @@ function M.setup(formatter_configs)
return
end
local formatters_by_ft = M.list_configured(formatter_configs)
null_ls.register { sources = formatters_by_ft.supported }
local formatters = M.list_configured(formatter_configs)
null_ls.register { sources = formatters.supported }
end
return M

View file

@ -9,7 +9,7 @@ function M:setup()
return
end
null_ls.config()
null_ls.config(lvim.lsp.null_ls.config)
local default_opts = require("lvim.lsp").get_common_opts()
if vim.tbl_isempty(lvim.lsp.null_ls.setup or {}) then

View file

@ -4,6 +4,8 @@ local null_ls = require "null-ls"
local services = require "lvim.lsp.null-ls.services"
local Log = require "lvim.core.log"
local is_registered = require("null-ls.sources").is_registered
function M.list_registered_providers(filetype)
local null_ls_methods = require "null-ls.methods"
local linter_method = null_ls_methods.internal["DIAGNOSTICS"]
@ -21,6 +23,7 @@ function M.list_available(filetype)
table.insert(linters, provider.name)
end
end
table.sort(linters)
return linters
end
@ -29,24 +32,29 @@ function M.list_configured(linter_configs)
local linters, errors = {}, {}
for _, lnt_config in pairs(linter_configs) do
local linter_name = lnt_config.exe:gsub("-", "_")
local linter = null_ls.builtins.diagnostics[linter_name]
local name = lnt_config.exe:gsub("-", "_")
local linter = null_ls.builtins.diagnostics[name]
if not linter then
Log:error("Not a valid linter: " .. lnt_config.exe)
errors[lnt_config.exe] = {} -- Add data here when necessary
elseif is_registered(lnt_config.exe) then
Log:trace "Skipping registering the source more than once"
else
local linter_cmd = services.find_command(linter._opts.command)
if not linter_cmd then
Log:warn("Not found: " .. linter._opts.command)
errors[lnt_config.exe] = {} -- Add data here when necessary
errors[name] = {} -- 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,
filetypes = lnt_config.filetypes,
}
table.insert(
linters,
linter.with {
command = linter_cmd,
extra_args = lnt_config.args,
filetypes = lnt_config.filetypes,
}
)
end
end
end

View file

@ -46,15 +46,13 @@ function M.find_command(command)
end
function M.list_registered_providers_names(filetype)
local u = require "null-ls.utils"
local c = require "null-ls.config"
local s = require "null-ls.sources"
local available_sources = s.get_available(filetype)
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
for _, source in ipairs(available_sources) do
for method in pairs(source.methods) do
registered[method] = registered[method] or {}
table.insert(registered[method], source.name)
end
end
return registered

View file

@ -2,7 +2,7 @@ local commit = {
packer = "7f62848f3a92eac61ae61def5f59ddb5e2cc6823",
lsp_config = "903a1fbca91b74e6fbc905366ce38364b9d7ba98",
nlsp_settings = "29f49afe27b43126d45a05baf3161a28b929f2f1",
null_ls = "3bf64acca268f3d7e0455501b82cf3f02f38c292",
null_ls = "cf2bc3185af066cb25f1bf6faa99727e2c47ef77",
fix_cursor_hold = "0e4e22d21975da60b0fd2d302285b3b603f9f71e",
lsp_installer = "37d9326f4ca4093b04eabdb697fec3764e226f88",
nvim_notify = "ee79a5e2f8bde0ebdf99880a98d1312da83a3caa",
@ -40,7 +40,10 @@ return {
{ "wbthomason/packer.nvim", commit = commit.packer },
{ "neovim/nvim-lspconfig", commit = commit.lsp_config },
{ "tamago324/nlsp-settings.nvim", commit = commit.nlsp_settings },
{ "jose-elias-alvarez/null-ls.nvim", commit = commit.null_ls },
{
"jose-elias-alvarez/null-ls.nvim",
commit = commit.null_ls,
},
{ "antoinemadec/FixCursorHold.nvim", commit = commit.fix_cursor_hold }, -- Needed while issue https://github.com/neovim/neovim/issues/12587 is still open
{
"williamboman/nvim-lsp-installer",