aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2025-02-25 09:17:51 +0800
committerGitHub <noreply@github.com>2025-02-25 01:17:51 +0000
commit095c0876c2010d6160df37cf057f2d0ad2c4501f (patch)
treea1ad1fbecda4626835bb415a3d4ee80f56c4362a /src/nvim/api
parent614c9322d50052c76fb3e6e1be7536a972ff0902 (diff)
downloadrneovim-095c0876c2010d6160df37cf057f2d0ad2c4501f.tar.gz
rneovim-095c0876c2010d6160df37cf057f2d0ad2c4501f.tar.bz2
rneovim-095c0876c2010d6160df37cf057f2d0ad2c4501f.zip
fix(api): don't override Vimscript SID (#32610)
Problem: When calling an API from Vimscript to set an option, mapping, etc., :verbose shows that it's set from an API client. Solution: Don't override current_sctx.sc_sid when calling an API from Vimscript. Also fix the inverse case where API channel id is not set when calling an API from RPC. Move channel id into sctx_T to make saving and restoring easier. Related #8329
Diffstat (limited to 'src/nvim/api')
-rw-r--r--src/nvim/api/private/helpers.c24
-rw-r--r--src/nvim/api/private/helpers.h8
2 files changed, 6 insertions, 26 deletions
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c
index a1af26e56f..cf82d907a3 100644
--- a/src/nvim/api/private/helpers.c
+++ b/src/nvim/api/private/helpers.c
@@ -1049,32 +1049,18 @@ const char *get_default_stl_hl(win_T *wp, bool use_winbar, int stc_hl_id)
}
}
-int find_sid(uint64_t channel_id)
-{
- switch (channel_id) {
- case VIML_INTERNAL_CALL:
- // TODO(autocmd): Figure out what this should be
- // return SID_API_CLIENT;
- case LUA_INTERNAL_CALL:
- return SID_LUA;
- default:
- return SID_API_CLIENT;
- }
-}
-
/// Sets sctx for API calls.
///
-/// @param channel_id api clients id. Used to determine if it's a internal
-/// call or a rpc call.
-/// @return returns previous value of current_sctx. To be used
-/// to be used for restoring sctx to previous state.
+/// @param channel_id api client id to determine if it's a internal or RPC call.
+///
+/// @return previous value of current_sctx. To be used later for restoring sctx.
sctx_T api_set_sctx(uint64_t channel_id)
{
sctx_T old_current_sctx = current_sctx;
if (channel_id != VIML_INTERNAL_CALL) {
- current_sctx.sc_sid =
- channel_id == LUA_INTERNAL_CALL ? SID_LUA : SID_API_CLIENT;
+ current_sctx.sc_sid = channel_id == LUA_INTERNAL_CALL ? SID_LUA : SID_API_CLIENT;
current_sctx.sc_lnum = 0;
+ current_sctx.sc_chan = channel_id;
}
return old_current_sctx;
}
diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h
index 5cf1ca4d34..d51f99e5ac 100644
--- a/src/nvim/api/private/helpers.h
+++ b/src/nvim/api/private/helpers.h
@@ -186,13 +186,7 @@ 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; \
+ const sctx_T save_current_sctx = api_set_sctx(channel_id); \
code; \
- current_channel_id = save_channel_id; \
current_sctx = save_current_sctx; \
} while (0);