aboutsummaryrefslogtreecommitdiff
path: root/test/functional/core/channels_spec.lua
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2025-03-08 07:29:45 +0800
committerGitHub <noreply@github.com>2025-03-08 07:29:45 +0800
commitf05a6666cfcb2cd95d860620748cb0fa58b23aba (patch)
tree5b573893d2596e2664290d914c56a31bf9932b60 /test/functional/core/channels_spec.lua
parent4a0e0e345340d715f784f317e99abfa71ecbc744 (diff)
downloadrneovim-f05a6666cfcb2cd95d860620748cb0fa58b23aba.tar.gz
rneovim-f05a6666cfcb2cd95d860620748cb0fa58b23aba.tar.bz2
rneovim-f05a6666cfcb2cd95d860620748cb0fa58b23aba.zip
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.
Diffstat (limited to 'test/functional/core/channels_spec.lua')
-rw-r--r--test/functional/core/channels_spec.lua49
1 files changed, 49 insertions, 0 deletions
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()