fix(lua): vim.wait(0) does not call loop_poll #39679

Problem:
Regression from c822a2657c: `vim.wait(0)` does not call `loop_poll`,
so `vim.wait(1)` is needed to "yield" from Lua.

Solution:
- Ensure that `vim._core.loop_poll()` is always called, even when `time=0`.
- Document how to interrupt Lua code (ctrl-c).

ref https://github.com/neovim/neovim/issues/6800
This commit is contained in:
Justin M. Keyes
2026-05-10 14:22:31 -04:00
committed by GitHub
parent c2d7dd781a
commit 5370eb0146
7 changed files with 81 additions and 14 deletions

View File

@@ -2567,6 +2567,26 @@ describe('lua stdlib', function()
end)
end)
it('lets CTRL-C interrupt a Lua loop', function()
api.nvim_set_var('channel', api.nvim_get_chan_info(0).id)
exec_lua([[
function _G.Loop()
vim.rpcnotify(vim.g.channel, 'ready')
while true do
local _, code = vim.wait(0, nil, 0)
if code == -2 then
vim.rpcnotify(vim.g.channel, 'wait', code)
return
end
end
end
]])
feed(':lua _G.Loop()<CR>')
eq({ 'notification', 'ready', {} }, next_msg(500))
feed('<C-C>')
eq({ 'notification', 'wait', { -2 } }, next_msg(500))
end)
it('fails in fast callbacks #26122', function()
local screen = Screen.new(80, 10)
exec_lua([[