fix(helpers): restore channel id after a call to WITH_SCRIPT_CONTEXT

In https://github.com/neovim/neovim/pull/22214, init_default_autocmds
has been turned into a lua function call to nvim_create_augroup and
nvim_create_autocmd.

This introduced a strange regression: a test in vim_spec.lua started
failing with its last_set_chan value switching from 0 to
-9223372036854775808.

It turns out that -9223372036854775808 is the value of LUA_INTERNAL_CALL
and would be inherited as last_set_chan by options set from the command
line due to the WITH_SCRIPT_CONTEXT macro not restoring the channel id
(WITH_SCRIPT_CONTEXT is used by nvim_create_augroup).
This commit is contained in:
glacambre 2023-02-11 13:51:33 +01:00
parent c9b0fe1f41
commit 5ca6cf55f9

View File

@ -175,11 +175,13 @@ typedef struct {
#define WITH_SCRIPT_CONTEXT(channel_id, code) \
do { \
const sctx_T save_current_sctx = current_sctx; \
const uint64_t save_channel_id = current_channel_id; \
current_sctx.sc_sid = \
(channel_id) == LUA_INTERNAL_CALL ? SID_LUA : SID_API_CLIENT; \
current_sctx.sc_lnum = 0; \
current_channel_id = channel_id; \
code; \
current_channel_id = save_channel_id; \
current_sctx = save_current_sctx; \
} while (0);