mirror of
https://github.com/LunarVim/LunarVim.git
synced 2024-09-21 02:55:09 +02:00
stop registering duplicate null-ls providers (#1240)
This commit is contained in:
parent
410354e7b1
commit
76a16b6676
1 changed files with 30 additions and 22 deletions
|
@ -23,7 +23,8 @@ function M.get_registered_providers_by_filetype(ft)
|
||||||
return matches
|
return matches
|
||||||
end
|
end
|
||||||
|
|
||||||
local function validate_nodejs_provider(requests, provider)
|
local function validate_nodejs_provider(provider)
|
||||||
|
local command_path
|
||||||
local root_dir
|
local root_dir
|
||||||
if lvim.builtin.rooter.active then
|
if lvim.builtin.rooter.active then
|
||||||
--- use vim-rooter to set root_dir
|
--- use vim-rooter to set root_dir
|
||||||
|
@ -41,43 +42,45 @@ local function validate_nodejs_provider(requests, provider)
|
||||||
local local_nodejs_command = root_dir .. "/node_modules/.bin/" .. provider._opts.command
|
local local_nodejs_command = root_dir .. "/node_modules/.bin/" .. provider._opts.command
|
||||||
u.lvim_log(string.format("checking [%s] for local node module: [%s]", local_nodejs_command, vim.inspect(provider)))
|
u.lvim_log(string.format("checking [%s] for local node module: [%s]", local_nodejs_command, vim.inspect(provider)))
|
||||||
if vim.fn.executable(local_nodejs_command) == 1 then
|
if vim.fn.executable(local_nodejs_command) == 1 then
|
||||||
provider._opts.command = local_nodejs_command
|
command_path = local_nodejs_command
|
||||||
table.insert(requests, provider)
|
|
||||||
elseif vim.fn.executable(provider._opts.command) == 1 then
|
elseif vim.fn.executable(provider._opts.command) == 1 then
|
||||||
u.lvim_log(string.format("checking in global path instead for node module: [%s]", provider._opts.command))
|
u.lvim_log(string.format("checking in global path instead for node module: [%s]", provider._opts.command))
|
||||||
table.insert(requests, provider)
|
command_path = provider._opts.command
|
||||||
else
|
else
|
||||||
u.lvim_log(string.format("Unable to find node module: [%s]", provider._opts.command))
|
u.lvim_log(string.format("Unable to find node module: [%s]", provider._opts.command))
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
return true
|
return command_path
|
||||||
end
|
end
|
||||||
|
|
||||||
local function validate_provider_request(requests, provider)
|
local function validate_provider_request(provider)
|
||||||
if provider == "" or provider == nil then
|
if provider == "" or provider == nil then
|
||||||
return false
|
return
|
||||||
end
|
end
|
||||||
-- NOTE: we can't use provider.name because eslint_d uses eslint name
|
-- NOTE: we can't use provider.name because eslint_d uses eslint name
|
||||||
if vim.tbl_contains(nodejs_local_providers, provider._opts.command) then
|
if vim.tbl_contains(nodejs_local_providers, provider._opts.command) then
|
||||||
return validate_nodejs_provider(requests, provider)
|
return validate_nodejs_provider(provider)
|
||||||
end
|
end
|
||||||
if vim.fn.executable(provider._opts.command) ~= 1 then
|
if vim.fn.executable(provider._opts.command) ~= 1 then
|
||||||
u.lvim_log(string.format("Unable to find the path for: [%s]", vim.inspect(provider)))
|
u.lvim_log(string.format("Unable to find the path for: [%s]", vim.inspect(provider)))
|
||||||
return false
|
return
|
||||||
end
|
end
|
||||||
table.insert(requests, provider)
|
return provider._opts.command
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO: for linters and formatters with spaces and '-' replace with '_'
|
-- TODO: for linters and formatters with spaces and '-' replace with '_'
|
||||||
function M.setup(filetype)
|
function M.setup(filetype)
|
||||||
for _, formatter in pairs(lvim.lang[filetype].formatters) do
|
for _, formatter in pairs(lvim.lang[filetype].formatters) do
|
||||||
local builtin_formatter = null_ls.builtins.formatting[formatter.exe]
|
local builtin_formatter = null_ls.builtins.formatting[formatter.exe]
|
||||||
|
if not vim.tbl_contains(M.requested_providers, builtin_formatter) then
|
||||||
-- FIXME: why doesn't this work?
|
-- FIXME: why doesn't this work?
|
||||||
-- builtin_formatter._opts.args = formatter.args or builtin_formatter._opts.args
|
-- builtin_formatter._opts.args = formatter.args or builtin_formatter._opts.args
|
||||||
-- builtin_formatter._opts.to_stdin = formatter.stdin or builtin_formatter._opts.to_stdin
|
-- builtin_formatter._opts.to_stdin = formatter.stdin or builtin_formatter._opts.to_stdin
|
||||||
if validate_provider_request(M.requested_providers, builtin_formatter) then
|
local resolved_path = validate_provider_request(builtin_formatter)
|
||||||
u.lvim_log(string.format("Using format provider: [%s]", formatter.exe))
|
if resolved_path then
|
||||||
|
builtin_formatter._opts.command = resolved_path
|
||||||
|
table.insert(M.requested_providers, builtin_formatter)
|
||||||
|
u.lvim_log(string.format("Using format provider: [%s]", builtin_formatter.name))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -89,11 +92,16 @@ function M.setup(filetype)
|
||||||
if linter.exe == "eslint_d" then
|
if linter.exe == "eslint_d" then
|
||||||
builtin_diagnoser = null_ls.builtins.diagnostics.eslint.with { command = "eslint_d" }
|
builtin_diagnoser = null_ls.builtins.diagnostics.eslint.with { command = "eslint_d" }
|
||||||
end
|
end
|
||||||
|
if not vim.tbl_contains(M.requested_providers, builtin_diagnoser) then
|
||||||
-- FIXME: why doesn't this work?
|
-- FIXME: why doesn't this work?
|
||||||
-- builtin_diagnoser._opts.args = linter.args or builtin_diagnoser._opts.args
|
-- builtin_diagnoser._opts.args = linter.args or builtin_diagnoser._opts.args
|
||||||
-- builtin_diagnoser._opts.to_stdin = linter.stdin or builtin_diagnoser._opts.to_stdin
|
-- builtin_diagnoser._opts.to_stdin = linter.stdin or builtin_diagnoser._opts.to_stdin
|
||||||
if validate_provider_request(M.requested_providers, builtin_diagnoser) then
|
local resolved_path = validate_provider_request(builtin_diagnoser)
|
||||||
u.lvim_log(string.format("Using linter provider: [%s]", linter.exe))
|
if resolved_path then
|
||||||
|
builtin_diagnoser._opts.command = resolved_path
|
||||||
|
table.insert(M.requested_providers, builtin_diagnoser)
|
||||||
|
u.lvim_log(string.format("Using linter provider: [%s]", builtin_diagnoser.name))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue