summaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2026-04-18 16:40:25 +0200
committerJustin M. Keyes <justinkz@gmail.com>2026-04-20 02:12:05 +0200
commitfe7218528d70b6df006c356761a92620f6a989c7 (patch)
treeeae903681838abeb8805449f92654d71cd258bde /src
parent5f6abd34f5c12534df0d79ee3507d40106ad505d (diff)
refactor(excmd): migrate ex_checkhealth to Lua
Diffstat (limited to 'src')
-rw-r--r--src/nvim/ex_docmd.c24
-rw-r--r--src/nvim/lua/executor.c63
2 files changed, 38 insertions, 49 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 34aef2e476..4b962da169 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -8197,23 +8197,11 @@ void set_pressedreturn(bool val)
/// ":checkhealth [plugins]"
static void ex_checkhealth(exarg_T *eap)
{
- Error err = ERROR_INIT;
- MAXSIZE_TEMP_ARRAY(args, 2);
-
- char mods[1024];
- size_t mods_len = 0;
- mods[0] = NUL;
-
- if (cmdmod.cmod_tab > 0 || cmdmod.cmod_split != 0) {
- bool multi_mods = false;
- mods_len = add_win_cmd_modifiers(mods, &cmdmod, &multi_mods);
- assert(mods_len < sizeof(mods));
- }
- ADD_C(args, STRING_OBJ(((String){ .data = mods, .size = mods_len })));
- ADD_C(args, CSTR_AS_OBJ(eap->arg));
-
- NLUA_EXEC_STATIC("vim.health._check(...)", args, kRetNilBool, NULL, &err);
- if (!ERROR_SET(&err)) {
+ // Suppress the Lua error (E5108) so the VIMRUNTIME diagnostic is the primary error.
+ emsg_off++;
+ bool ok = nlua_call_excmd("vim.health", "_check", eap, &cmdmod);
+ emsg_off--;
+ if (ok) {
return;
}
@@ -8228,8 +8216,6 @@ static void ex_checkhealth(exarg_T *eap)
emsg(_("E5009: Invalid 'runtimepath'"));
}
}
- semsg_multiline("emsg", err.msg);
- api_clear_error(&err);
}
static void ex_terminal(exarg_T *eap)
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c
index e0e3f5ef9f..d7e3ce6d83 100644
--- a/src/nvim/lua/executor.c
+++ b/src/nvim/lua/executor.c
@@ -198,36 +198,6 @@ static void nlua_push_eap(lua_State *lstate, exarg_T *eap, const cmdmod_T *cmod)
lua_setfield(lstate, -2, "smods");
}
-/// Calls Lua to implement an excmd. Passes `eap` + `cmdmod` to Lua as a dict arg, which is arranged
-/// to match the Lua type `vim.api.keyset.create_user_command.command_args`.
-///
-/// @param module Lua module name, e.g. "vim._core.ex_cmd".
-/// @param func Function name in the module, e.g. "ex_log".
-/// @param eap Excmd args.
-/// @param cmod Excmd mods.
-void nlua_call_excmd(const char *module, const char *func, exarg_T *eap, const cmdmod_T *cmod)
-{
- lua_State *const lstate = global_lstate;
-
- lua_getglobal(lstate, "require");
- lua_pushstring(lstate, module);
- if (lua_pcall(lstate, 1, 1, 0) != 0) {
- semsg("E5108: %s", lua_tostring(lstate, -1));
- lua_pop(lstate, 1);
- return;
- }
- lua_getfield(lstate, -1, func);
- lua_remove(lstate, -2);
-
- lua_newtable(lstate);
- nlua_push_eap(lstate, eap, cmod);
-
- if (nlua_pcall(lstate, 1, 0)) {
- semsg("E5108: %s", lua_tostring(lstate, -1));
- lua_pop(lstate, 1);
- }
-}
-
#if __has_feature(address_sanitizer)
static bool nlua_track_refs = false;
# define NLUA_TRACK_REFS
@@ -1788,6 +1758,39 @@ void nlua_call_vimfn(const char *module, const char *func, typval_T *argvars, ty
nlua_typval_exec(buf, strlen(buf), module, argvars, argcount, false, rettv);
}
+/// Calls Lua to implement an excmd. Passes `eap` + `cmdmod` to Lua as a dict arg, which is arranged
+/// to match the Lua type `vim.api.keyset.create_user_command.command_args`.
+///
+/// @param module Lua module name, e.g. "vim._core.ex_cmd".
+/// @param func Function name in the module, e.g. "ex_log".
+/// @param eap Excmd args.
+/// @param cmod Excmd mods.
+/// @return true on success, false on error (message already emitted).
+bool nlua_call_excmd(const char *module, const char *func, exarg_T *eap, const cmdmod_T *cmod)
+{
+ lua_State *const lstate = global_lstate;
+
+ lua_getglobal(lstate, "require");
+ lua_pushstring(lstate, module);
+ if (lua_pcall(lstate, 1, 1, 0) != 0) {
+ semsg("E5108: %s", lua_tostring(lstate, -1));
+ lua_pop(lstate, 1);
+ return false;
+ }
+ lua_getfield(lstate, -1, func);
+ lua_remove(lstate, -2);
+
+ lua_newtable(lstate);
+ nlua_push_eap(lstate, eap, cmod);
+
+ if (nlua_pcall(lstate, 1, 0)) {
+ semsg("E5108: %s", lua_tostring(lstate, -1));
+ lua_pop(lstate, 1);
+ return false;
+ }
+ return true;
+}
+
/// Checks if a LuaRef refers to a function.
bool nlua_ref_is_function(LuaRef ref)
{