diff options
author | zeertzjq <zeertzjq@outlook.com> | 2025-02-25 09:17:51 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-25 01:17:51 +0000 |
commit | 095c0876c2010d6160df37cf057f2d0ad2c4501f (patch) | |
tree | a1ad1fbecda4626835bb415a3d4ee80f56c4362a /src/nvim/eval.c | |
parent | 614c9322d50052c76fb3e6e1be7536a972ff0902 (diff) | |
download | rneovim-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/eval.c')
-rw-r--r-- | src/nvim/eval.c | 28 |
1 files changed, 6 insertions, 22 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 5b91f1248f..18f83bfb6b 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -1368,7 +1368,7 @@ int eval_foldexpr(win_T *wp, int *cp) const bool use_sandbox = was_set_insecurely(wp, kOptFoldexpr, OPT_LOCAL); char *arg = skipwhite(wp->w_p_fde); - current_sctx = wp->w_p_script_ctx[kWinOptFoldexpr].script_ctx; + current_sctx = wp->w_p_script_ctx[kWinOptFoldexpr]; emsg_off++; if (use_sandbox) { @@ -7655,14 +7655,10 @@ hashtab_T *find_var_ht_dict(const char *name, const size_t name_len, const char // for behavioral consistency. With this different anonymous exec from // same file can't access each others script local stuff. We need to do // this all other cases except this will act like that otherwise. - const LastSet last_set = (LastSet){ - .script_ctx = current_sctx, - .channel_id = LUA_INTERNAL_CALL, - }; bool should_free; // should_free is ignored as script_ctx will be resolved to a fname // and new_script_item() will consume it. - char *sc_name = get_scriptname(last_set, &should_free); + char *sc_name = get_scriptname(current_sctx, &should_free); new_script_item(sc_name, ¤t_sctx.sc_sid); } } @@ -8043,31 +8039,19 @@ void var_set_global(const char *const name, typval_T vartv) /// Should only be invoked when 'verbose' is non-zero. void last_set_msg(sctx_T script_ctx) { - const LastSet last_set = (LastSet){ - .script_ctx = script_ctx, - .channel_id = 0, - }; - option_last_set_msg(last_set); -} - -/// Displays where an option was last set. -/// -/// Should only be invoked when 'verbose' is non-zero. -void option_last_set_msg(LastSet last_set) -{ - if (last_set.script_ctx.sc_sid == 0) { + if (script_ctx.sc_sid == 0) { return; } bool should_free; - char *p = get_scriptname(last_set, &should_free); + char *p = get_scriptname(script_ctx, &should_free); verbose_enter(); msg_puts(_("\n\tLast set from ")); msg_puts(p); - if (last_set.script_ctx.sc_lnum > 0) { + if (script_ctx.sc_lnum > 0) { msg_puts(_(line_msg)); - msg_outnum(last_set.script_ctx.sc_lnum); + msg_outnum(script_ctx.sc_lnum); } if (should_free) { xfree(p); |