diff options
author | Lewis Russell <lewis6991@gmail.com> | 2024-12-13 10:51:33 +0000 |
---|---|---|
committer | Lewis Russell <me@lewisr.dev> | 2024-12-13 14:36:24 +0000 |
commit | 9c20342297391c4076809964e799f2c7705b819b (patch) | |
tree | 7cd408a979aae4da77cb993b6a60cc3cd624d307 /test/functional/plugin/lsp_spec.lua | |
parent | 7940ec69136fa992c98aa7b37265fbc2e619232e (diff) | |
download | rneovim-9c20342297391c4076809964e799f2c7705b819b.tar.gz rneovim-9c20342297391c4076809964e799f2c7705b819b.tar.bz2 rneovim-9c20342297391c4076809964e799f2c7705b819b.zip |
fix(lsp): reuse client if configs match and no root dir
Problem:
An LSP configuration that creates client with no root_dir or
workspace_folders can result in vim.lsp.enable attaching to it multiple
times.
Solution:
When checking existing clients, reuse a client if it wasn't initially
configured have any workspace_folders. This more closely matches the
behaviour we had prior to d9235ef
Diffstat (limited to 'test/functional/plugin/lsp_spec.lua')
-rw-r--r-- | test/functional/plugin/lsp_spec.lua | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 79952cb933..d2ef166983 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -5184,8 +5184,8 @@ describe('LSP', function() local win = vim.api.nvim_get_current_win() vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, { 'local x = 10', '', 'print(x)' }) vim.api.nvim_win_set_cursor(win, { 3, 6 }) - local client_id1 = assert(vim.lsp.start({ name = 'dummy', cmd = server1.cmd })) - local client_id2 = assert(vim.lsp.start({ name = 'dummy', cmd = server2.cmd })) + local client_id1 = assert(vim.lsp.start({ name = 'dummy1', cmd = server1.cmd })) + local client_id2 = assert(vim.lsp.start({ name = 'dummy2', cmd = server2.cmd })) local response vim.lsp.buf.definition({ on_list = function(r) @@ -6203,5 +6203,33 @@ describe('LSP', function() end) ) end) + + it('does not attach to buffers more than once if no root_dir', function() + exec_lua(create_server_definition) + + local tmp1 = t.tmpname(true) + + eq( + 1, + exec_lua(function() + local server = _G._create_server({ + handlers = { + initialize = function(_, _, callback) + callback(nil, { capabilities = {} }) + end, + }, + }) + + vim.lsp.config('foo', { cmd = server.cmd, filetypes = { 'foo' } }) + vim.lsp.enable('foo') + + vim.cmd.edit(assert(tmp1)) + vim.bo.filetype = 'foo' + vim.bo.filetype = 'foo' + + return #vim.lsp.get_clients({ bufnr = vim.api.nvim_get_current_buf() }) + end) + ) + end) end) end) |