test(lsp): fix fake LSP server timeout not working (#37970)

Problem:  Fake LSP server does not timeout or respond to SIGTERM as it
          does not run the event loop.
Solution: Instead of io.read(), use stdioopen()'s on_stdin callback to
          accumulate input and use vim.wait() to wait for input.

Also, in the test suite, don't stop a session when it's not running, as
calling uv.stop() outside uv.run() will instead cause the next uv.run()
to stop immediately, which cancels the next RPC request.
This commit is contained in:
zeertzjq authored and GitHub committed 2026-02-19 10:38:14 -08:00
1 parent 08f4811061
commit dec3c6fa34
4 files changed
+62 -26

No files matched your search

+12 -14
View File
@@ -88,7 +88,11 @@ describe('LSP', function()
after_each(function()
stop()
exec_lua('vim.iter(lsp.get_clients()):each(function(client) client:stop(true) end)')
exec_lua(function()
vim.iter(vim.lsp.get_clients({ _uninitialized = true })):each(function(client)
client:stop(true)
end)
end)
api.nvim_exec_autocmds('VimLeavePre', { modeline = false })
end)
@@ -206,18 +210,18 @@ describe('LSP', function()
it('does not reuse an already-stopping client #33616', function()
-- we immediately try to start a second client with the same name/root
-- before the first one has finished shutting down; we must get a new id.
local clients = exec_lua([[
local client1 = vim.lsp.start({
local clients = exec_lua(function()
local client1 = assert(vim.lsp.start({
name = 'dup-test',
cmd = { vim.v.progpath, '-l', fake_lsp_code, 'basic_init' },
}, { attach = false })
}, { attach = false }))
vim.lsp.get_client_by_id(client1):stop()
local client2 = vim.lsp.start({
local client2 = assert(vim.lsp.start({
name = 'dup-test',
cmd = { vim.v.progpath, '-l', fake_lsp_code, 'basic_init' },
}, { attach = false })
}, { attach = false }))
return { client1, client2 }
]])
end)
local c1, c2 = clients[1], clients[2]
eq(false, c1 == c2, 'Expected a fresh client while the old one is stopping')
end)
@@ -320,14 +324,8 @@ describe('LSP', function()
)
it('should succeed with manual shutdown', function()
if is_ci() then
pending('hangs the build on CI #14028, re-enable with freeze timeout #14204')
return
elseif t.skip_fragile(pending) then
return
end
local expected_handlers = {
{ NIL, {}, { method = 'shutdown', bufnr = 1, client_id = 1, version = 0 } },
{ NIL, {}, { method = 'shutdown', bufnr = 1, client_id = 1, request_id = 2, version = 0 } },
{ NIL, {}, { method = 'test', client_id = 1 } },
}
test_rpc_server {