diff options
| author | Justin M. Keyes <justinkz@gmail.com> | 2026-04-18 16:57:20 +0200 |
|---|---|---|
| committer | Justin M. Keyes <justinkz@gmail.com> | 2026-04-20 02:12:05 +0200 |
| commit | b8dcb348391d6364e9d082a0abe8f0e2872f8c48 (patch) | |
| tree | 3f6b663704b28a896c13055e924ac2f075398014 /src | |
| parent | fe7218528d70b6df006c356761a92620f6a989c7 (diff) | |
refactor(excmd): migrate help.c to Lua
Diffstat (limited to 'src')
| -rw-r--r-- | src/nvim/help.c | 53 |
1 files changed, 20 insertions, 33 deletions
diff --git a/src/nvim/help.c b/src/nvim/help.c index 2928647e6b..78e2690772 100644 --- a/src/nvim/help.c +++ b/src/nvim/help.c @@ -14,6 +14,7 @@ #include "nvim/cmdexpand.h" #include "nvim/cmdexpand_defs.h" #include "nvim/errors.h" +#include "nvim/eval/typval.h" #include "nvim/ex_cmds.h" #include "nvim/ex_cmds_defs.h" #include "nvim/ex_docmd.h" @@ -105,16 +106,14 @@ void ex_help(exarg_T *eap) // ":help!" (bang, no args): DWIM help, resolve best tag at cursor via Lua. char *allocated_arg = NULL; if (helpbang) { - Error err = ERROR_INIT; - Object res = NLUA_EXEC_STATIC("return require'vim._core.help'.resolve_tag()", - (Array)ARRAY_DICT_INIT, kRetObject, NULL, &err); - if (!ERROR_SET(&err) && res.type == kObjectTypeString && res.data.string.size > 0) { - allocated_arg = xstrdup(res.data.string.data); + typval_T no_args[] = { { .v_type = VAR_UNKNOWN } }; + typval_T rettv; + nlua_call_vimfn("vim._core.help", "resolve_tag", no_args, &rettv); + if (rettv.v_type == VAR_STRING && rettv.vval.v_string != NULL && *rettv.vval.v_string != NUL) { + allocated_arg = rettv.vval.v_string; // takes ownership arg = allocated_arg; - } - api_free_object(res); - api_clear_error(&err); - if (allocated_arg == NULL) { + } else { + tv_clear(&rettv); emsg(_(e_noident)); return; } @@ -335,24 +334,18 @@ static int help_compare(const void *s1, const void *s2) /// When "keep_lang" is true try keeping the language of the current buffer. int find_help_tags(const char *arg, int *num_matches, char ***matches, bool keep_lang) { - Error err = ERROR_INIT; - MAXSIZE_TEMP_ARRAY(args, 1); - - ADD_C(args, CSTR_AS_OBJ(arg)); - - Object res = NLUA_EXEC_STATIC("return require'vim._core.help'.escape_subject(...)", - args, kRetObject, NULL, &err); - - if (ERROR_SET(&err)) { - emsg_multiline(err.msg, "lua_error", HLF_E, true); - api_clear_error(&err); + typval_T tv_args[] = { + { .v_type = VAR_STRING, .vval.v_string = (char *)arg }, + { .v_type = VAR_UNKNOWN }, + }; + typval_T rettv; + nlua_call_vimfn("vim._core.help", "escape_subject", tv_args, &rettv); + if (rettv.v_type != VAR_STRING || rettv.vval.v_string == NULL) { + tv_clear(&rettv); return FAIL; } - api_clear_error(&err); - - assert(res.type == kObjectTypeString); - xstrlcpy(IObuff, res.data.string.data, sizeof(IObuff)); - api_free_object(res); + xstrlcpy(IObuff, rettv.vval.v_string, sizeof(IObuff)); + tv_clear(&rettv); *matches = NULL; *num_matches = 0; @@ -467,14 +460,8 @@ void prepare_help_buffer(void) /// Populate *local-additions* in help.txt void get_local_additions(void) { - Error err = ERROR_INIT; - Object res = NLUA_EXEC_STATIC("return require'vim._core.help'.local_additions()", - (Array)ARRAY_DICT_INIT, kRetNilBool, NULL, &err); - if (ERROR_SET(&err)) { - emsg_multiline(err.msg, "lua_error", HLF_E, true); - } - api_free_object(res); - api_clear_error(&err); + typval_T no_args[] = { { .v_type = VAR_UNKNOWN } }; + nlua_call_vimfn("vim._core.help", "local_additions", no_args, NULL); } /// ":exusage" |
