mirror of
https://github.com/neovim/neovim.git
synced 2026-05-25 22:38:29 +00:00
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:
@@ -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([[
|
||||
|
||||
Reference in New Issue
Block a user