From 03e34d426021ab71287ce5a0ef7c79dd6b004023 Mon Sep 17 00:00:00 2001 From: William Boman Date: Thu, 28 Apr 2022 23:21:15 +0200 Subject: [PATCH] chore(lsp): remove usage of deprecated lsp_installer.on_server_ready() --- lua/user/lsp/configs.lua | 24 ++++++++++++++++++++++++ lua/user/lsp/init.lua | 2 +- lua/user/lsp/lsp-installer.lua | 28 ---------------------------- 3 files changed, 25 insertions(+), 29 deletions(-) create mode 100644 lua/user/lsp/configs.lua delete mode 100644 lua/user/lsp/lsp-installer.lua diff --git a/lua/user/lsp/configs.lua b/lua/user/lsp/configs.lua new file mode 100644 index 0000000..71d5ed0 --- /dev/null +++ b/lua/user/lsp/configs.lua @@ -0,0 +1,24 @@ +local status_ok, lsp_installer = pcall(require, "nvim-lsp-installer") +if not status_ok then + return +end + +local lspconfig = require("lspconfig") + +local servers = { "jsonls", "sumneko_lua" } + +lsp_installer.setup { + ensure_installed = servers +} + +for _, server in pairs(servers) do + local opts = { + on_attach = require("user.lsp.handlers").on_attach, + capabilities = require("user.lsp.handlers").capabilities, + } + local has_custom_opts, server_custom_opts = pcall(require, "user.lsp.settings." .. server) + if has_custom_opts then + opts = vim.tbl_deep_extend("force", server_custom_opts, opts) + end + lspconfig[server].setup(opts) +end diff --git a/lua/user/lsp/init.lua b/lua/user/lsp/init.lua index 8158cf3..24e42db 100644 --- a/lua/user/lsp/init.lua +++ b/lua/user/lsp/init.lua @@ -3,6 +3,6 @@ if not status_ok then return end -require "user.lsp.lsp-installer" +require "user.lsp.configs" require("user.lsp.handlers").setup() require "user.lsp.null-ls" diff --git a/lua/user/lsp/lsp-installer.lua b/lua/user/lsp/lsp-installer.lua deleted file mode 100644 index 2fe4af2..0000000 --- a/lua/user/lsp/lsp-installer.lua +++ /dev/null @@ -1,28 +0,0 @@ -local status_ok, lsp_installer = pcall(require, "nvim-lsp-installer") -if not status_ok then - return -end - --- Register a handler that will be called for all installed servers. --- Alternatively, you may also register handlers on specific server instances instead (see example below). -lsp_installer.on_server_ready(function(server) - local opts = { - on_attach = require("user.lsp.handlers").on_attach, - capabilities = require("user.lsp.handlers").capabilities, - } - - if server.name == "jsonls" then - local jsonls_opts = require("user.lsp.settings.jsonls") - opts = vim.tbl_deep_extend("force", jsonls_opts, opts) - end - - if server.name == "sumneko_lua" then - local sumneko_opts = require("user.lsp.settings.sumneko_lua") - opts = vim.tbl_deep_extend("force", sumneko_opts, opts) - end - - -- 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) -end) -