diff options
author | bfredl <bjorn.linse@gmail.com> | 2023-08-01 23:19:17 +0200 |
---|---|---|
committer | bfredl <bjorn.linse@gmail.com> | 2023-08-04 08:45:19 +0200 |
commit | c01e624b0762b24a4988bf9474a57d5b6278d180 (patch) | |
tree | 177ed97c1dea240ecfa476a34ed40d6203f152f2 | |
parent | cc87dda31a5b5637ade7ddcfe5199f2df5fd47df (diff) | |
download | rneovim-c01e624b0762b24a4988bf9474a57d5b6278d180.tar.gz rneovim-c01e624b0762b24a4988bf9474a57d5b6278d180.tar.bz2 rneovim-c01e624b0762b24a4988bf9474a57d5b6278d180.zip |
feat(lua): more specific error messages for vim.api type checking
-rw-r--r-- | src/nvim/generators/gen_api_dispatch.lua | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/nvim/generators/gen_api_dispatch.lua b/src/nvim/generators/gen_api_dispatch.lua index 1b0565d9b6..fe63cb883e 100644 --- a/src/nvim/generators/gen_api_dispatch.lua +++ b/src/nvim/generators/gen_api_dispatch.lua @@ -558,6 +558,7 @@ local function process_function(fn) static int %s(lua_State *lstate) { Error err = ERROR_INIT; + char *err_param = 0; if (lua_gettop(lstate) != %i) { api_set_error(&err, kErrorTypeValidation, "Expected %i argument%s"); goto exit_0; @@ -605,6 +606,7 @@ local function process_function(fn) extra = "true, " end local errshift = 0 + local seterr = '' if string.match(param_type, '^KeyDict_') then write_shifted_output(output, string.format([[ %s %s = { 0 }; nlua_pop_keydict(lstate, &%s, %s_get_field, %s&err);]], param_type, cparam, cparam, param_type, extra)) @@ -613,11 +615,13 @@ local function process_function(fn) else write_shifted_output(output, string.format([[ const %s %s = nlua_pop_%s(lstate, %s&err);]], param[1], cparam, param_type, extra)) + seterr = [[ + err_param = "]]..param[2]..[[";]] end write_shifted_output(output, string.format([[ - if (ERROR_SET(&err)) { + if (ERROR_SET(&err)) {]]..seterr..[[ goto exit_%u; } @@ -661,9 +665,14 @@ local function process_function(fn) exit_0: if (ERROR_SET(&err)) { luaL_where(lstate, 1); + if (err_param) { + lua_pushstring(lstate, "param '"); + lua_pushstring(lstate, err_param); + lua_pushstring(lstate, "': "); + } lua_pushstring(lstate, err.msg); api_clear_error(&err); - lua_concat(lstate, 2); + lua_concat(lstate, err_param ? 5 : 2); return lua_error(lstate); } ]] |