aboutsummaryrefslogtreecommitdiff
path: root/test/functional/plugin/lsp_spec.lua
diff options
context:
space:
mode:
authorGregory Anders <greg@gpanders.com>2025-01-14 08:19:54 -0600
committerGitHub <noreply@github.com>2025-01-14 08:19:54 -0600
commite8a6c1b02122852da83dc52184e78369598d8240 (patch)
tree4e3b5c9f33957d81885c7888eb168aa8979a1b29 /test/functional/plugin/lsp_spec.lua
parentf1c45fc7a4a595e460cd245172a5767bddeb09e9 (diff)
downloadrneovim-e8a6c1b02122852da83dc52184e78369598d8240.tar.gz
rneovim-e8a6c1b02122852da83dc52184e78369598d8240.tar.bz2
rneovim-e8a6c1b02122852da83dc52184e78369598d8240.zip
fix(lsp): schedule call to vim.lsp.start for async root_dir (#31998)
When `root_dir` is a function it can (and often will) call the provided callback function in a fast API context (e.g. in the `on_exit` handler of `vim.system`). When the callback function is executed we should ensure that it runs vim.lsp.start on the main event loop.
Diffstat (limited to 'test/functional/plugin/lsp_spec.lua')
-rw-r--r--test/functional/plugin/lsp_spec.lua53
1 files changed, 29 insertions, 24 deletions
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua
index 5e9766c784..db3ab8ed98 100644
--- a/test/functional/plugin/lsp_spec.lua
+++ b/test/functional/plugin/lsp_spec.lua
@@ -6259,37 +6259,42 @@ describe('LSP', function()
)
end)
- it('supports a function for root_dir', function()
+ it('supports async function for root_dir', function()
exec_lua(create_server_definition)
local tmp1 = t.tmpname(true)
+ exec_lua(function()
+ local server = _G._create_server({
+ handlers = {
+ initialize = function(_, _, callback)
+ callback(nil, { capabilities = {} })
+ end,
+ },
+ })
- eq(
- 'some_dir',
- 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' },
- root_dir = function(cb)
+ vim.lsp.config('foo', {
+ cmd = server.cmd,
+ filetypes = { 'foo' },
+ root_dir = function(cb)
+ vim.system({ 'sleep', '0' }, {}, function()
cb('some_dir')
- end,
- })
- vim.lsp.enable('foo')
+ end)
+ end,
+ })
+ vim.lsp.enable('foo')
- vim.cmd.edit(assert(tmp1))
- vim.bo.filetype = 'foo'
+ vim.cmd.edit(assert(tmp1))
+ vim.bo.filetype = 'foo'
+ end)
- return vim.lsp.get_clients({ bufnr = vim.api.nvim_get_current_buf() })[1].root_dir
- end)
- )
+ retry(nil, 1000, function()
+ eq(
+ 'some_dir',
+ exec_lua(function()
+ return vim.lsp.get_clients({ bufnr = vim.api.nvim_get_current_buf() })[1].root_dir
+ end)
+ )
+ end)
end)
end)
end)