diff --git a/lua/lsp/efm-ls.lua b/lua/lsp/efm-ls.lua index 1ed99eb..5892b5a 100644 --- a/lua/lsp/efm-ls.lua +++ b/lua/lsp/efm-ls.lua @@ -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}, @@ -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 diff --git a/lua/lsp/go-ls.lua b/lua/lsp/go-ls.lua index de522e4..ef6be94 100644 --- a/lua/lsp/go-ls.lua +++ b/lua/lsp/go-ls.lua @@ -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}, @@ -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 diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index fcb323e..43c2e63 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -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 diff --git a/lua/lsp/lua-ls.lua b/lua/lsp/lua-ls.lua index 969ed37..a005e95 100644 --- a/lua/lsp/lua-ls.lua +++ b/lua/lsp/lua-ls.lua @@ -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 = { @@ -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 diff --git a/lua/lsp/rust-ls.lua b/lua/lsp/rust-ls.lua index b284a26..f7672a0 100644 --- a/lua/lsp/rust-ls.lua +++ b/lua/lsp/rust-ls.lua @@ -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( @@ -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), diff --git a/lua/lsps.lua b/lua/lsps.lua index 2f2b006..999f424 100644 --- a/lua/lsps.lua +++ b/lua/lsps.lua @@ -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)