From f05a6666cfcb2cd95d860620748cb0fa58b23aba Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 8 Mar 2025 07:29:45 +0800 Subject: fix(events): always allow some events to be nested (#32706) Always allow the following four events to be nested, as they may contain important information, and are triggered on the event loop, which may be processed by a blocking call inside another autocommand. - ChanInfo - ChanOpen - TermRequest - TermResponse There are some other events that are triggered on the event loop, but they are mostly triggered by user actions in a UI client, and therefore not very likely to happen during another autocommand, so leave them unchanged for now. --- test/functional/core/channels_spec.lua | 49 ++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'test/functional/core') diff --git a/test/functional/core/channels_spec.lua b/test/functional/core/channels_spec.lua index 7b10eb05ef..11617905dd 100644 --- a/test/functional/core/channels_spec.lua +++ b/test/functional/core/channels_spec.lua @@ -3,6 +3,8 @@ local n = require('test.functional.testnvim')() local clear, eq, eval, next_msg, ok, source = n.clear, t.eq, n.eval, n.next_msg, t.ok, n.source local command, fn, api = n.command, n.fn, n.api +local feed = n.feed +local exec_lua = n.exec_lua local matches = t.matches local sleep = vim.uv.sleep local get_session, set_session = n.get_session, n.set_session @@ -416,6 +418,53 @@ describe('channels', function() -- works correctly with no output eq({ 'notification', 'exit', { id, 1, { '' } } }, next_msg()) end) + + it('ChanOpen works with vim.wait() from another autocommand #32706', function() + exec_lua([[ + vim.api.nvim_create_autocmd('ChanOpen', { + callback = function(ev) + _G.chan = vim.v.event.info.id + end, + }) + vim.api.nvim_create_autocmd('InsertEnter', { + buffer = 0, + callback = function() + local chan = vim.fn.jobstart({ 'cat' }) + _G.result = vim.wait(3000, function() + return _G.chan == chan + end) + end, + }) + ]]) + feed('i') + retry(nil, 4000, function() + eq(true, exec_lua('return _G.result')) + end) + end) + + it('ChanInfo works with vim.wait() from another autocommand #32706', function() + exec_lua([[ + vim.api.nvim_create_autocmd('ChanInfo', { + callback = function(ev) + _G.foo = vim.v.event.info.client.attributes.foo + end, + }) + vim.api.nvim_create_autocmd('InsertEnter', { + buffer = 0, + callback = function() + local chan = vim.fn.jobstart({ 'cat' }) + _G.result = vim.wait(3000, function() + return _G.foo == 'bar' + end) + end, + }) + ]]) + feed('i') + api.nvim_set_client_info('test', {}, 'remote', {}, { foo = 'bar' }) + retry(nil, 4000, function() + eq(true, exec_lua('return _G.result')) + end) + end) end) describe('loopback', function() -- cgit