1
0
mirror of https://github.com/jdhao/nvim-config.git synced 2025-06-08 14:14:33 +02:00

fix: check if language server exists before using

This commit is contained in:
jdhao 2022-01-28 13:13:24 +08:00
parent 597b11638f
commit 38883b3fc5

View File

@ -1,6 +1,8 @@
local api = vim.api local api = vim.api
local lsp = vim.lsp local lsp = vim.lsp
local utils = require("utils")
local M = {} local M = {}
function M.show_line_diagnostics() function M.show_line_diagnostics()
@ -73,54 +75,72 @@ capabilities.textDocument.completion.completionItem.snippetSupport = true
local lspconfig = require("lspconfig") local lspconfig = require("lspconfig")
lspconfig.pylsp.setup({ if utils.executable('pylsp') then
on_attach = custom_attach, lspconfig.pylsp.setup({
settings = { on_attach = custom_attach,
pylsp = { settings = {
plugins = { pylsp = {
pylint = { enabled = true, executable = "pylint" }, plugins = {
pyflakes = { enabled = false }, pylint = { enabled = true, executable = "pylint" },
pycodestyle = { enabled = false }, pyflakes = { enabled = false },
jedi_completion = { fuzzy = true }, pycodestyle = { enabled = false },
pyls_isort = { enabled = true }, jedi_completion = { fuzzy = true },
pylsp_mypy = { enabled = true }, pyls_isort = { enabled = true },
pylsp_mypy = { enabled = true },
},
}, },
}, },
}, flags = {
flags = { debounce_text_changes = 200,
debounce_text_changes = 200, },
}, capabilities = capabilities,
capabilities = capabilities, })
}) else
vim.notify("pylsp not found!", 'warn', {title = 'Nvim-config'})
end
-- lspconfig.pyright.setup{ -- if utils.executable('pyright') then
-- on_attach = custom_attach, -- lspconfig.pyright.setup{
-- capabilities = capabilities -- on_attach = custom_attach,
-- } -- capabilities = capabilities
-- }
-- else
-- vim.notify("pyright not found!", 'warn', {title = 'Nvim-config'})
-- end
lspconfig.clangd.setup({ if utils.executable('clangd') then
on_attach = custom_attach, lspconfig.clangd.setup({
capabilities = capabilities, on_attach = custom_attach,
filetypes = { "c", "cpp", "cc" }, capabilities = capabilities,
flags = { filetypes = { "c", "cpp", "cc" },
debounce_text_changes = 500, flags = {
}, debounce_text_changes = 500,
}) },
})
else
vim.notify("clangd not found!", 'warn', {title = 'Nvim-config'})
end
-- set up vim-language-server -- set up vim-language-server
lspconfig.vimls.setup({ if utils.executable('vim-language-server') then
on_attach = custom_attach, lspconfig.vimls.setup({
flags = { on_attach = custom_attach,
debounce_text_changes = 500, flags = {
}, debounce_text_changes = 500,
capabilities = capabilities, },
}) capabilities = capabilities,
})
else
vim.notify("vim-language-server not found!", 'warn', {title = 'Nvim-config'})
end
-- set up bash-language-server -- set up bash-language-server
lspconfig.bashls.setup({ if utils.executable('bash-language-server') then
on_attach = custom_attach, lspconfig.bashls.setup({
capabilities = capabilities, on_attach = custom_attach,
}) capabilities = capabilities,
})
end
local sumneko_binary_path = vim.fn.exepath("lua-language-server") local sumneko_binary_path = vim.fn.exepath("lua-language-server")
if vim.g.is_mac or vim.g.is_linux and sumneko_binary_path ~= "" then if vim.g.is_mac or vim.g.is_linux and sumneko_binary_path ~= "" then