From 090c8a87b31de5c5a21eebc55adb22ddab625015 Mon Sep 17 00:00:00 2001 From: William Boman Date: Wed, 27 Apr 2022 21:20:45 +0200 Subject: feat: integrate with lspconfig's on_setup hook (#631) * feat: integrate with lspconfig's on_setup hook * fix!: don't use aliased installation directories if new .setup() fn is used This makes it so servers are always installed in a directory name that corresponds with the server name. The reason aliased installation directories is supported is lost on me, but it's legacy and complicates things unnecessarily. This is a breaking change for users who previously were using the `.on_server_ready()` hook, and now transitioned to setting up servers directly via lspconfig. These users will need to reinstall the server. * fix: block usage of the deprecated server:setup() method if new setup method is used * fix: allow passing no arg to setup() * docs: ok final.v3 readme --- tests/middleware_spec.lua | 39 +++++++++++++++++++++++++++++++++++++++ tests/minimal_debug_init.lua | 16 ++++++---------- 2 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 tests/middleware_spec.lua (limited to 'tests') diff --git a/tests/middleware_spec.lua b/tests/middleware_spec.lua new file mode 100644 index 00000000..5c629ee6 --- /dev/null +++ b/tests/middleware_spec.lua @@ -0,0 +1,39 @@ +local util = require "lspconfig.util" +local servers = require "nvim-lsp-installer.servers" +local middleware = require "nvim-lsp-installer.middleware" + +describe("middleware", function() + it("should register on_setup hook with lspconfig", function() + -- 1. setup dummy server + local default_options = { + cmd = { "dummy-lsp" }, + cmd_env = { PATH = "/keep/my/path/out/your/f/mouth" }, + } + local server = ServerGenerator { + name = "dummy", + default_options = default_options, + } + servers.register(server) + + -- 2. register hook + middleware.register_lspconfig_hook() + + -- 3. call lspconfig hook + local config = { + name = "dummy", + cmd = { "should", "be", "overwritten" }, + custom = "setting", + cmd_env = { SOME_DEFAULT_ENV = "important" }, + } + util.on_setup(config) + assert.are.same({ + cmd = { "dummy-lsp" }, + name = "dummy", + custom = "setting", + cmd_env = { + PATH = "/keep/my/path/out/your/f/mouth", + SOME_DEFAULT_ENV = "important", + }, + }, config) + end) +end) diff --git a/tests/minimal_debug_init.lua b/tests/minimal_debug_init.lua index cd42ed24..f090b353 100644 --- a/tests/minimal_debug_init.lua +++ b/tests/minimal_debug_init.lua @@ -32,25 +32,21 @@ local function load_plugins() end function _G.load_config() - -- ================================================== - -- ======= MODIFY YOUR CONFIG HERE, IF NEEDED ======= - -- ================================================== - local lsp_installer = require "nvim-lsp-installer" + local lspconfig = require "lspconfig" local function on_attach(client, bufnr) vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc") end - require("nvim-lsp-installer").settings { + require("nvim-lsp-installer").setup { log = vim.log.levels.DEBUG, } - lsp_installer.on_server_ready(function(server) - server:setup { - on_attach = on_attach, - } - end) -- ================================================== + -- ========= SETUP RELEVANT SERVER(S) HERE! ========= + -- ================================================== + -- + -- lspconfig.sumneko_lua.setup { on_attach = on_attach } end if vim.fn.isdirectory(install_path) == 0 then -- cgit v1.2.3-70-g09d2