mirror of
https://github.com/neovim/neovim.git
synced 2026-05-04 04:55:16 +00:00
test(lsp): make async format test work properly (#35794)
Overriding vim.lsp.handlers['textDocument/formatting'] doesn't work here because fake_lsp_server_setup() uses a table with __index to specify client handlers, which takes priority over vim.lsp.handlers[], and as a result the overridden handler is never called, and the test ends before the vim.wait() even finishes. Instead, set a global variable from the handler that is actually reached (by vim.rpcrequest() from client handler), and avoid stopping the event loop too early.
This commit is contained in:
@@ -5313,22 +5313,18 @@ describe('LSP', function()
|
||||
notify_msg = msg
|
||||
end
|
||||
|
||||
local handler = vim.lsp.handlers['textDocument/formatting']
|
||||
local handler_called = false
|
||||
vim.lsp.handlers['textDocument/formatting'] = function()
|
||||
handler_called = true
|
||||
end
|
||||
|
||||
_G.handler_called = false
|
||||
vim.lsp.buf.format({ bufnr = bufnr, async = true })
|
||||
vim.wait(1000, function()
|
||||
return handler_called
|
||||
return _G.handler_called
|
||||
end)
|
||||
|
||||
vim.notify = notify
|
||||
vim.lsp.handlers['textDocument/formatting'] = handler
|
||||
return { notify = notify_msg, handler_called = handler_called }
|
||||
return { notify_msg = notify_msg, handler_called = _G.handler_called }
|
||||
end)
|
||||
eq({ handler_called = true }, result)
|
||||
elseif ctx.method == 'textDocument/formatting' then
|
||||
exec_lua('_G.handler_called = true')
|
||||
elseif ctx.method == 'shutdown' then
|
||||
client:stop()
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user