mirror of
https://github.com/neovim/neovim.git
synced 2025-09-08 12:28:18 +00:00
Merge pull request #15079 from shadmansaleh/feat/verbose_lua
feat(lua): add :verbose support for lua config
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include "nvim/change.h"
|
||||
#include "nvim/cursor.h"
|
||||
#include "nvim/eval/userfunc.h"
|
||||
#include "nvim/eval/typval.h"
|
||||
#include "nvim/event/loop.h"
|
||||
#include "nvim/event/time.h"
|
||||
#include "nvim/ex_cmds2.h"
|
||||
@@ -652,6 +653,15 @@ static int nlua_state_init(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL
|
||||
// [package, loaded, module]
|
||||
lua_setfield(lstate, -2, "vim.filetype"); // [package, loaded]
|
||||
|
||||
code = (char *)&lua_keymap_module[0];
|
||||
if (luaL_loadbuffer(lstate, code, sizeof(lua_keymap_module) - 1, "@vim/keymap.lua")
|
||||
|| nlua_pcall(lstate, 0, 1)) {
|
||||
nlua_error(lstate, _("E5106: Error while creating vim.keymap module: %.*s"));
|
||||
return 1;
|
||||
}
|
||||
// [package, loaded, module]
|
||||
lua_setfield(lstate, -2, "vim.keymap"); // [package, loaded]
|
||||
|
||||
lua_pop(lstate, 2); // []
|
||||
}
|
||||
|
||||
@@ -1811,6 +1821,58 @@ void nlua_execute_on_key(int c)
|
||||
#endif
|
||||
}
|
||||
|
||||
// Sets the editor "script context" during Lua execution. Used by :verbose.
|
||||
// @param[out] current
|
||||
void nlua_set_sctx(sctx_T *current)
|
||||
{
|
||||
if (p_verbose <= 0 || current->sc_sid != SID_LUA) {
|
||||
return;
|
||||
}
|
||||
lua_State *const lstate = global_lstate;
|
||||
lua_Debug *info = (lua_Debug *)xmalloc(sizeof(lua_Debug));
|
||||
|
||||
// Files where internal wrappers are defined so we can ignore them
|
||||
// like vim.o/opt etc are defined in _meta.lua
|
||||
char *ignorelist[] = {
|
||||
"vim/_meta.lua",
|
||||
"vim/keymap.lua",
|
||||
};
|
||||
int ignorelist_size = sizeof(ignorelist) / sizeof(ignorelist[0]);
|
||||
|
||||
for (int level = 1; true; level++) {
|
||||
if (lua_getstack(lstate, level, info) != 1) {
|
||||
goto cleanup;
|
||||
}
|
||||
if (lua_getinfo(lstate, "nSl", info) == 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
bool is_ignored = false;
|
||||
if (info->what[0] == 'C' || info->source[0] != '@') {
|
||||
is_ignored = true;
|
||||
} else {
|
||||
for (int i = 0; i < ignorelist_size; i++) {
|
||||
if (strncmp(ignorelist[i], info->source+1, strlen(ignorelist[i])) == 0) {
|
||||
is_ignored = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (is_ignored) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
char *source_path = fix_fname(info->source + 1);
|
||||
get_current_script_id((char_u *)source_path, current);
|
||||
xfree(source_path);
|
||||
current->sc_lnum = info->currentline;
|
||||
current->sc_seq = -1;
|
||||
|
||||
cleanup:
|
||||
xfree(info);
|
||||
}
|
||||
|
||||
void nlua_do_ucmd(ucmd_T *cmd, exarg_T *eap)
|
||||
{
|
||||
lua_State *const lstate = global_lstate;
|
||||
|
Reference in New Issue
Block a user