diff options
author | zeertzjq <zeertzjq@outlook.com> | 2025-02-26 07:40:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-25 23:40:21 +0000 |
commit | e2aca58bcc4f0aff8da9683194e4dc857a56118f (patch) | |
tree | d077b324c29de6d53ca42f9496efb9451fc40b05 /src/nvim/api | |
parent | af0a2157ad2958b6c1e3c374ac247726c252c219 (diff) | |
download | rneovim-e2aca58bcc4f0aff8da9683194e4dc857a56118f.tar.gz rneovim-e2aca58bcc4f0aff8da9683194e4dc857a56118f.tar.bz2 rneovim-e2aca58bcc4f0aff8da9683194e4dc857a56118f.zip |
fix(lua): don't override script ID from :source (#32626)
Problem: When setting an option, mapping etc. from Lua without -V1, the
script ID is set to SID_LUA even if there already is a script
ID assigned by :source.
Solution: Don't set script ID to SID_LUA if it is already a Lua script.
Also add _editor.lua to ignorelist to make script context more
useful when using vim.cmd().
Diffstat (limited to 'src/nvim/api')
-rw-r--r-- | src/nvim/api/private/helpers.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index cf82d907a3..eca442845d 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -30,6 +30,7 @@ #include "nvim/message.h" #include "nvim/msgpack_rpc/unpacker.h" #include "nvim/pos_defs.h" +#include "nvim/runtime.h" #include "nvim/types_defs.h" #ifdef INCLUDE_GENERATED_DECLARATIONS @@ -1057,10 +1058,18 @@ const char *get_default_stl_hl(win_T *wp, bool use_winbar, int stc_hl_id) sctx_T api_set_sctx(uint64_t channel_id) { sctx_T old_current_sctx = current_sctx; + // The script context is already properly set when calling an API from Vimscript. if (channel_id != VIML_INTERNAL_CALL) { - 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; + if (channel_id == LUA_INTERNAL_CALL) { + // When the current script is a Lua script, don't override sc_sid. + if (!script_is_lua(current_sctx.sc_sid)) { + current_sctx.sc_sid = SID_LUA; + } + } else { + current_sctx.sc_sid = SID_API_CLIENT; + current_sctx.sc_chan = channel_id; + } } return old_current_sctx; } |