aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/runtime.c
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/runtime.c
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/runtime.c')
-rw-r--r--src/nvim/runtime.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c
index cdedf86977..de58c81441 100644
--- a/src/nvim/runtime.c
+++ b/src/nvim/runtime.c
@@ -270,17 +270,13 @@ list_T *stacktrace_create(void)
ufunc_T *const fp = entry->es_info.ufunc;
const sctx_T sctx = fp->uf_script_ctx;
bool filepath_alloced = false;
- char *filepath = sctx.sc_sid > 0
- ? get_scriptname((LastSet){ .script_ctx = sctx },
- &filepath_alloced) : "";
+ char *filepath = sctx.sc_sid > 0 ? get_scriptname(sctx, &filepath_alloced) : "";
lnum += sctx.sc_lnum;
stacktrace_push_item(l, fp, NULL, lnum, filepath, filepath_alloced);
} else if (entry->es_type == ETYPE_AUCMD) {
const sctx_T sctx = entry->es_info.aucmd->script_ctx;
bool filepath_alloced = false;
- char *filepath = sctx.sc_sid > 0
- ? get_scriptname((LastSet){ .script_ctx = sctx },
- &filepath_alloced) : "";
+ char *filepath = sctx.sc_sid > 0 ? get_scriptname(sctx, &filepath_alloced) : "";
lnum += sctx.sc_lnum;
stacktrace_push_item(l, NULL, entry->es_name, lnum, filepath, filepath_alloced);
}
@@ -2426,11 +2422,11 @@ void scriptnames_slash_adjust(void)
/// Get a pointer to a script name. Used for ":verbose set".
/// Message appended to "Last set from "
-char *get_scriptname(LastSet last_set, bool *should_free)
+char *get_scriptname(sctx_T script_ctx, bool *should_free)
{
*should_free = false;
- switch (last_set.script_ctx.sc_sid) {
+ switch (script_ctx.sc_sid) {
case SID_MODELINE:
return _("modeline");
case SID_CMDARG:
@@ -2446,15 +2442,15 @@ char *get_scriptname(LastSet last_set, bool *should_free)
case SID_LUA:
return _("Lua (run Nvim with -V1 for more details)");
case SID_API_CLIENT:
- snprintf(IObuff, IOSIZE, _("API client (channel id %" PRIu64 ")"), last_set.channel_id);
+ snprintf(IObuff, IOSIZE, _("API client (channel id %" PRIu64 ")"), script_ctx.sc_chan);
return IObuff;
case SID_STR:
return _("anonymous :source");
default: {
- char *const sname = SCRIPT_ITEM(last_set.script_ctx.sc_sid)->sn_name;
+ char *const sname = SCRIPT_ITEM(script_ctx.sc_sid)->sn_name;
if (sname == NULL) {
snprintf(IObuff, IOSIZE, _("anonymous :source (script id %d)"),
- last_set.script_ctx.sc_sid);
+ script_ctx.sc_sid);
return IObuff;
}