diff options
author | Michael Strobel <71396679+Kibadda@users.noreply.github.com> | 2025-03-30 20:07:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-30 11:07:53 -0700 |
commit | 90d15227c55c9ae6e4d52884817db75e4329792b (patch) | |
tree | 495e6455629eb5dafd880409bc3e58ee076d319c /test/functional/plugin/lsp_spec.lua | |
parent | de96063bda43273f94478af2b02b5f5487b4f3f2 (diff) | |
download | rneovim-90d15227c55c9ae6e4d52884817db75e4329792b.tar.gz rneovim-90d15227c55c9ae6e4d52884817db75e4329792b.tar.bz2 rneovim-90d15227c55c9ae6e4d52884817db75e4329792b.zip |
feat(lsp): workspace_required #31824
Problem:
Some language servers do not work properly without a workspace folder.
Solution:
Add `workspace_required`, which skips starting the lsp client if no
workspace folder is found.
Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
Diffstat (limited to 'test/functional/plugin/lsp_spec.lua')
-rw-r--r-- | test/functional/plugin/lsp_spec.lua | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 614c49a41f..856c086add 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -6414,5 +6414,40 @@ describe('LSP', function() filetypes = true, }, 'cannot start foo due to config error: .* filetypes: expected table, got boolean') end) + + it('does not start without workspace if workspace_required=true', function() + exec_lua(create_server_definition) + + local tmp1 = t.tmpname(true) + + eq( + { workspace_required = false }, + exec_lua(function() + local server = _G._create_server({ + handlers = { + initialize = function(_, _, callback) + callback(nil, { capabilities = {} }) + end, + }, + }) + + local ws_required = { cmd = server.cmd, workspace_required = true, filetypes = { 'foo' } } + local ws_not_required = vim.deepcopy(ws_required) + ws_not_required.workspace_required = false + + vim.lsp.config('ws_required', ws_required) + vim.lsp.config('ws_not_required', ws_not_required) + vim.lsp.enable('ws_required') + vim.lsp.enable('ws_not_required') + + vim.cmd.edit(assert(tmp1)) + vim.bo.filetype = 'foo' + + local clients = vim.lsp.get_clients({ bufnr = vim.api.nvim_get_current_buf() }) + assert(1 == #clients) + return { workspace_required = clients[1].config.workspace_required } + end) + ) + end) end) end) |