mirror of
https://github.com/neovim/neovim.git
synced 2025-09-27 13:38:34 +00:00
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
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user