Skip to content

Commit

Permalink
refactor and properly setup cmp_nvim_lsp for all LSPs
Browse files Browse the repository at this point in the history
  • Loading branch information
Samyak2 committed Jul 18, 2022
1 parent 5e2389b commit d1d38ae
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions lua/lsp/efm-ls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ local server_available, requested_server = lsp_installer_servers.get_server("efm

if server_available then
requested_server:on_ready(function()
requested_server:setup{
local opts = vim.tbl_deep_extend("force", require("lsp").common_opts, {
-- cmd = {vim.fn.stdpath('data') .. "/lspinstall/efm/efm-langserver"},
-- init_options = {initializationOptions},
init_options = {documentFormatting = true, codeAction = true},
Expand Down Expand Up @@ -120,8 +120,8 @@ if server_available then
"lua", "python", "javascriptreact", "javascript", "typescript", "typescriptreact", "sh", "html", "css",
"json", "yaml", "markdown", "vue"
},
on_attach = require'lsp'.common_on_attach
}
})
requested_server:setup(opts)
end)
if not requested_server:is_installed() then
-- Queue the server to be installed
Expand Down
6 changes: 3 additions & 3 deletions lua/lsp/go-ls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local server_available, requested_server = lsp_installer_servers.get_server("gop

if server_available then
requested_server:on_ready(function()
requested_server:setup{
local opts = vim.tbl_deep_extend("force", require("lsp").common_opts, {
settings = {
gopls = {
analyses = {unusedparams = true, fieldalignment = true, nilness = true},
Expand All @@ -13,8 +13,8 @@ if server_available then
}
},
init_options = {usePlaceholders = true, completeUnimported = true},
on_attach = require'lsp'.common_on_attach
}
})
requested_server:setup(opts)
end)
if not requested_server:is_installed() then
-- Queue the server to be installed
Expand Down
7 changes: 7 additions & 0 deletions lua/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,11 @@ function ret.common_on_attach(client, bufnr)
-- end
end

ret.common_opts = {
capabilities = require('cmp_nvim_lsp').update_capabilities(
vim.lsp.protocol.make_client_capabilities()
),
on_attach = ret.common_on_attach,
}

return ret
6 changes: 3 additions & 3 deletions lua/lsp/lua-ls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ local lsp_installer_servers = require 'nvim-lsp-installer.servers'
local server_available, requested_server = lsp_installer_servers.get_server("sumneko_lua")
if server_available then
requested_server:on_ready(function()
requested_server:setup{
local opts = vim.tbl_deep_extend("force", require("lsp").common_opts, {
-- cmd = {sumneko_binary, "-E", sumneko_root_path .. "/main.lua"};
settings = {
Lua = {
Expand All @@ -44,8 +44,8 @@ if server_available then
telemetry = {enable = false}
}
},
on_attach = require'lsp'.common_on_attach
}
})
requested_server:setup(opts)
end)
if not requested_server:is_installed() then
-- Queue the server to be installed
Expand Down
5 changes: 2 additions & 3 deletions lua/lsp/rust-ls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ if server_available then
local codelldb_path = extension_path .. 'adapter/codelldb'
local liblldb_path = extension_path .. 'lldb/lib/liblldb.so'

local opts = {
on_attach = require('lsp').common_on_attach,
local opts = vim.tbl_deep_extend("force", require("lsp").common_opts, {
autoSetHints = true,
-- dap = {
-- adapter = require('rust-tools.dap').get_codelldb_adapter(
Expand All @@ -23,7 +22,7 @@ if server_available then
debuggables = {
use_telescope = true
},
}
})

require("rust-tools").setup{
server = vim.tbl_deep_extend("force", requested_server:get_default_options(), opts),
Expand Down
8 changes: 1 addition & 7 deletions lua/lsps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,13 @@ local lsp_installer = require("nvim-lsp-installer")

-- Register a handler that will be called for all installed servers.
lsp_installer.on_server_ready(function(server)
local opts = {
capabilities = require('cmp_nvim_lsp').update_capabilities(
vim.lsp.protocol.make_client_capabilities()
)
}
local opts = vim.tbl_deep_extend("force", require("lsp").common_opts, {})

-- ignore the ones that are setup manually later, with more options and stuff
if server.name == "efm" or server.name == "sumneko_lua" or server.name == "gopls" or server.name == "rust_analyzer" then
return
end

opts.on_attach = require('lsp').common_on_attach

-- This setup() function is exactly the same as lspconfig's setup function.
-- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
server:setup(opts)
Expand Down

0 comments on commit d1d38ae

Please sign in to comment.