use on_init to check golangci_lint_ls version
also ensure language servers are compatible with navbuddy before registering them
This commit is contained in:
@ -1,5 +1,25 @@
|
||||
local M = {}
|
||||
local enable = {
|
||||
['golangci_lint_ls'] = function()
|
||||
local enable = true
|
||||
local ok, _ = pcall(function()
|
||||
vim
|
||||
.system({ 'golangci-lint', '--version' }, { text = true }, function(out)
|
||||
if out.code ~= 0 then
|
||||
enable = false
|
||||
return
|
||||
end
|
||||
if out.stdout:match ' 1%.%d+%.%d+' then
|
||||
enable = false
|
||||
return
|
||||
end
|
||||
end)
|
||||
:wait()
|
||||
end)
|
||||
|
||||
return enable and ok
|
||||
end,
|
||||
}
|
||||
function M.setup()
|
||||
local servers = {
|
||||
ts_ls = { filetypes = { 'javascript', 'typescript', 'javascriptreact', 'typescriptreact' } },
|
||||
@ -21,29 +41,29 @@ function M.setup()
|
||||
},
|
||||
},
|
||||
},
|
||||
golangci_lint_ls = require 'plugins.lsp.golangci_lint_ls',
|
||||
golangci_lint_ls = {
|
||||
filetypes = { 'go' },
|
||||
on_init = function(client)
|
||||
local name = client.name
|
||||
if enable[name] then
|
||||
if not enable[name]() then
|
||||
vim.notify('Disabling language server ' .. name, vim.log.levels.WARN)
|
||||
vim.lsp.enable(client.name, false)
|
||||
return
|
||||
end
|
||||
end
|
||||
end,
|
||||
},
|
||||
erlangls = { cmd = { '/home/fergusmolloy/.local/bin/erlang_ls' }, filetypes = { 'erlang' } },
|
||||
elixirls = { cmd = { 'elixir-ls' }, filetypes = { 'elixir' } },
|
||||
lua_ls = require 'plugins.lsp.lua_ls',
|
||||
}
|
||||
|
||||
local on_attach = require 'plugins.lsp.on_attach'
|
||||
local lspconfig = require 'lspconfig'
|
||||
|
||||
for server, config in pairs(servers) do
|
||||
if config['enable'] then
|
||||
if not config.enable() then
|
||||
vim.notify('Disabling language server ' .. server, vim.log.levels.WARN)
|
||||
goto continue
|
||||
end
|
||||
end
|
||||
|
||||
config.capabilities = require('blink.cmp').get_lsp_capabilities(config.capabilities)
|
||||
config.on_attach = require 'plugins.lsp.on_attach'
|
||||
vim.lsp.enable(server)
|
||||
vim.lsp.config(server, config)
|
||||
|
||||
::continue::
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user