mirror of
https://github.com/LunarVim/LunarVim.git
synced 2025-08-28 22:08:12 +02:00
feat: support new null-ls (#1955)
This commit is contained in:
parent
cad6355929
commit
abc9f2764d
7 changed files with 48 additions and 30 deletions
|
@ -20,6 +20,7 @@ end
|
||||||
local function make_formatters_info(ft)
|
local function make_formatters_info(ft)
|
||||||
local null_formatters = require "lvim.lsp.null-ls.formatters"
|
local null_formatters = require "lvim.lsp.null-ls.formatters"
|
||||||
local registered_formatters = null_formatters.list_registered_providers(ft)
|
local registered_formatters = null_formatters.list_registered_providers(ft)
|
||||||
|
-- print("reg", vim.inspect(registered_formatters))
|
||||||
local supported_formatters = null_formatters.list_available(ft)
|
local supported_formatters = null_formatters.list_available(ft)
|
||||||
local section = {
|
local section = {
|
||||||
"Formatters info",
|
"Formatters info",
|
||||||
|
|
|
@ -40,6 +40,7 @@ return {
|
||||||
},
|
},
|
||||||
null_ls = {
|
null_ls = {
|
||||||
setup = {},
|
setup = {},
|
||||||
|
config = {},
|
||||||
},
|
},
|
||||||
override = {
|
override = {
|
||||||
"angularls",
|
"angularls",
|
||||||
|
|
|
@ -4,6 +4,8 @@ local null_ls = require "null-ls"
|
||||||
local services = require "lvim.lsp.null-ls.services"
|
local services = require "lvim.lsp.null-ls.services"
|
||||||
local Log = require "lvim.core.log"
|
local Log = require "lvim.core.log"
|
||||||
|
|
||||||
|
local is_registered = require("null-ls.sources").is_registered
|
||||||
|
|
||||||
function M.list_registered_providers(filetype)
|
function M.list_registered_providers(filetype)
|
||||||
local null_ls_methods = require "null-ls.methods"
|
local null_ls_methods = require "null-ls.methods"
|
||||||
local formatter_method = null_ls_methods.internal["FORMATTING"]
|
local formatter_method = null_ls_methods.internal["FORMATTING"]
|
||||||
|
@ -30,24 +32,29 @@ function M.list_configured(formatter_configs)
|
||||||
local formatters, errors = {}, {}
|
local formatters, errors = {}, {}
|
||||||
|
|
||||||
for _, fmt_config in ipairs(formatter_configs) do
|
for _, fmt_config in ipairs(formatter_configs) do
|
||||||
local formatter_name = fmt_config.exe:gsub("-", "_")
|
local name = fmt_config.exe:gsub("-", "_")
|
||||||
local formatter = null_ls.builtins.formatting[formatter_name]
|
local formatter = null_ls.builtins.formatting[name]
|
||||||
|
|
||||||
if not formatter then
|
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
|
errors[name] = {} -- Add data here when necessary
|
||||||
|
elseif is_registered(fmt_config.exe) then
|
||||||
|
Log:trace "Skipping registering the source more than once"
|
||||||
else
|
else
|
||||||
local formatter_cmd = services.find_command(formatter._opts.command)
|
local formatter_cmd = services.find_command(formatter._opts.command)
|
||||||
if not formatter_cmd then
|
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
|
errors[name] = {} -- Add data here when necessary
|
||||||
else
|
else
|
||||||
Log:debug("Using formatter: " .. formatter_cmd)
|
Log:debug("Using formatter: " .. formatter_cmd)
|
||||||
formatters[fmt_config.exe] = formatter.with {
|
table.insert(
|
||||||
command = formatter_cmd,
|
formatters,
|
||||||
extra_args = fmt_config.args,
|
formatter.with {
|
||||||
filetypes = fmt_config.filetypes,
|
command = formatter_cmd,
|
||||||
}
|
extra_args = fmt_config.args,
|
||||||
|
filetypes = fmt_config.filetypes,
|
||||||
|
}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -60,8 +67,8 @@ function M.setup(formatter_configs)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local formatters_by_ft = M.list_configured(formatter_configs)
|
local formatters = M.list_configured(formatter_configs)
|
||||||
null_ls.register { sources = formatters_by_ft.supported }
|
null_ls.register { sources = formatters.supported }
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
@ -9,7 +9,7 @@ function M:setup()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
null_ls.config()
|
null_ls.config(lvim.lsp.null_ls.config)
|
||||||
local default_opts = require("lvim.lsp").get_common_opts()
|
local default_opts = require("lvim.lsp").get_common_opts()
|
||||||
|
|
||||||
if vim.tbl_isempty(lvim.lsp.null_ls.setup or {}) then
|
if vim.tbl_isempty(lvim.lsp.null_ls.setup or {}) then
|
||||||
|
|
|
@ -4,6 +4,8 @@ local null_ls = require "null-ls"
|
||||||
local services = require "lvim.lsp.null-ls.services"
|
local services = require "lvim.lsp.null-ls.services"
|
||||||
local Log = require "lvim.core.log"
|
local Log = require "lvim.core.log"
|
||||||
|
|
||||||
|
local is_registered = require("null-ls.sources").is_registered
|
||||||
|
|
||||||
function M.list_registered_providers(filetype)
|
function M.list_registered_providers(filetype)
|
||||||
local null_ls_methods = require "null-ls.methods"
|
local null_ls_methods = require "null-ls.methods"
|
||||||
local linter_method = null_ls_methods.internal["DIAGNOSTICS"]
|
local linter_method = null_ls_methods.internal["DIAGNOSTICS"]
|
||||||
|
@ -21,6 +23,7 @@ function M.list_available(filetype)
|
||||||
table.insert(linters, provider.name)
|
table.insert(linters, provider.name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
table.sort(linters)
|
table.sort(linters)
|
||||||
return linters
|
return linters
|
||||||
end
|
end
|
||||||
|
@ -29,24 +32,29 @@ function M.list_configured(linter_configs)
|
||||||
local linters, errors = {}, {}
|
local linters, errors = {}, {}
|
||||||
|
|
||||||
for _, lnt_config in pairs(linter_configs) do
|
for _, lnt_config in pairs(linter_configs) do
|
||||||
local linter_name = lnt_config.exe:gsub("-", "_")
|
local name = lnt_config.exe:gsub("-", "_")
|
||||||
local linter = null_ls.builtins.diagnostics[linter_name]
|
local linter = null_ls.builtins.diagnostics[name]
|
||||||
|
|
||||||
if not linter then
|
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
|
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
|
else
|
||||||
local linter_cmd = services.find_command(linter._opts.command)
|
local linter_cmd = services.find_command(linter._opts.command)
|
||||||
if not linter_cmd then
|
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
|
errors[name] = {} -- Add data here when necessary
|
||||||
else
|
else
|
||||||
Log:debug("Using linter: " .. linter_cmd)
|
Log:debug("Using linter: " .. linter_cmd)
|
||||||
linters[lnt_config.exe] = linter.with {
|
table.insert(
|
||||||
command = linter_cmd,
|
linters,
|
||||||
extra_args = lnt_config.args,
|
linter.with {
|
||||||
filetypes = lnt_config.filetypes,
|
command = linter_cmd,
|
||||||
}
|
extra_args = lnt_config.args,
|
||||||
|
filetypes = lnt_config.filetypes,
|
||||||
|
}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -46,15 +46,13 @@ function M.find_command(command)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.list_registered_providers_names(filetype)
|
function M.list_registered_providers_names(filetype)
|
||||||
local u = require "null-ls.utils"
|
local s = require "null-ls.sources"
|
||||||
local c = require "null-ls.config"
|
local available_sources = s.get_available(filetype)
|
||||||
local registered = {}
|
local registered = {}
|
||||||
for method, source in pairs(c.get()._methods) do
|
for _, source in ipairs(available_sources) do
|
||||||
for name, filetypes in pairs(source) do
|
for method in pairs(source.methods) do
|
||||||
if u.filetype_matches(filetypes, filetype) then
|
registered[method] = registered[method] or {}
|
||||||
registered[method] = registered[method] or {}
|
table.insert(registered[method], source.name)
|
||||||
table.insert(registered[method], name)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return registered
|
return registered
|
||||||
|
|
|
@ -2,7 +2,7 @@ local commit = {
|
||||||
packer = "7f62848f3a92eac61ae61def5f59ddb5e2cc6823",
|
packer = "7f62848f3a92eac61ae61def5f59ddb5e2cc6823",
|
||||||
lsp_config = "903a1fbca91b74e6fbc905366ce38364b9d7ba98",
|
lsp_config = "903a1fbca91b74e6fbc905366ce38364b9d7ba98",
|
||||||
nlsp_settings = "29f49afe27b43126d45a05baf3161a28b929f2f1",
|
nlsp_settings = "29f49afe27b43126d45a05baf3161a28b929f2f1",
|
||||||
null_ls = "3bf64acca268f3d7e0455501b82cf3f02f38c292",
|
null_ls = "cf2bc3185af066cb25f1bf6faa99727e2c47ef77",
|
||||||
fix_cursor_hold = "0e4e22d21975da60b0fd2d302285b3b603f9f71e",
|
fix_cursor_hold = "0e4e22d21975da60b0fd2d302285b3b603f9f71e",
|
||||||
lsp_installer = "37d9326f4ca4093b04eabdb697fec3764e226f88",
|
lsp_installer = "37d9326f4ca4093b04eabdb697fec3764e226f88",
|
||||||
nvim_notify = "ee79a5e2f8bde0ebdf99880a98d1312da83a3caa",
|
nvim_notify = "ee79a5e2f8bde0ebdf99880a98d1312da83a3caa",
|
||||||
|
@ -40,7 +40,10 @@ return {
|
||||||
{ "wbthomason/packer.nvim", commit = commit.packer },
|
{ "wbthomason/packer.nvim", commit = commit.packer },
|
||||||
{ "neovim/nvim-lspconfig", commit = commit.lsp_config },
|
{ "neovim/nvim-lspconfig", commit = commit.lsp_config },
|
||||||
{ "tamago324/nlsp-settings.nvim", commit = commit.nlsp_settings },
|
{ "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
|
{ "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",
|
"williamboman/nvim-lsp-installer",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue