mirror of
https://github.com/neovim/neovim.git
synced 2025-10-09 11:26:37 +00:00
backport: feat(lsp): pass resolved config to cmd() #34560
Problem:
In LSP configs, the function form of `cmd()` cannot easily get the
resolved root dir (workspace). One of the main use-cases of a dynamic
`cmd()` is to be able to start a new server whose binary may be located
*in the workspace* ([example](https://github.com/neovim/nvim-lspconfig/pull/3912)).
Compare `reuse_client()`, which also receives the resolved config.
Solution:
Pass the resolved config to `cmd()`.
(cherry picked from commit 32f30c4874
)
Co-authored-by: Julian Visser <12615757+justmejulian@users.noreply.github.com>
This commit is contained in:
@@ -54,7 +54,7 @@ M.create_server_definition = function()
|
||||
local server = {}
|
||||
server.messages = {}
|
||||
|
||||
function server.cmd(dispatchers)
|
||||
function server.cmd(dispatchers, _config)
|
||||
local closing = false
|
||||
local handlers = opts.handlers or {}
|
||||
local srv = {}
|
||||
|
@@ -6490,7 +6490,7 @@ describe('LSP', function()
|
||||
)
|
||||
end)
|
||||
|
||||
it('supports async function for root_dir', function()
|
||||
it('async root_dir, cmd(…,config) gets resolved config', function()
|
||||
exec_lua(create_server_definition)
|
||||
|
||||
local tmp1 = t.tmpname(true)
|
||||
@@ -6504,7 +6504,10 @@ describe('LSP', function()
|
||||
})
|
||||
|
||||
vim.lsp.config('foo', {
|
||||
cmd = server.cmd,
|
||||
cmd = function(dispatchers, config)
|
||||
_G.test_resolved_root = config.root_dir --[[@type string]]
|
||||
return server.cmd(dispatchers, config)
|
||||
end,
|
||||
filetypes = { 'foo' },
|
||||
root_dir = function(bufnr, cb)
|
||||
assert(tmp1 == vim.api.nvim_buf_get_name(bufnr))
|
||||
@@ -6527,6 +6530,12 @@ describe('LSP', function()
|
||||
end)
|
||||
)
|
||||
end)
|
||||
eq(
|
||||
'some_dir',
|
||||
exec_lua(function()
|
||||
return _G.test_resolved_root
|
||||
end)
|
||||
)
|
||||
end)
|
||||
|
||||
it('starts correct LSP and stops incorrect LSP when filetype changes', function()
|
||||
@@ -6784,10 +6793,8 @@ describe('LSP', function()
|
||||
markers_resolve_to({ 'marker_a', { 'marker_b', 'marker_d' } }, tmp_root)
|
||||
markers_resolve_to({ 'foo', { 'bar', 'baz' }, 'marker_d' }, dir_b)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('vim.lsp.is_enabled()', function()
|
||||
it('works', function()
|
||||
it('vim.lsp.is_enabled()', function()
|
||||
exec_lua(function()
|
||||
vim.lsp.config('foo', {
|
||||
cmd = { 'foo' },
|
||||
|
Reference in New Issue
Block a user