mirror of
https://github.com/neovim/neovim.git
synced 2024-12-24 05:05:00 -07:00
feat(lua): specific error messages for type checking opts
params
This commit is contained in:
parent
7bc93e0e2f
commit
6c0812d92e
@ -134,6 +134,8 @@ The following new APIs and features were added.
|
|||||||
• `vim.fn.*`
|
• `vim.fn.*`
|
||||||
• `vim.api.*`
|
• `vim.api.*`
|
||||||
|
|
||||||
|
• Improved messages for type errors in `vim.api.*` calls (including `opts` params)
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
CHANGED FEATURES *news-changed*
|
CHANGED FEATURES *news-changed*
|
||||||
|
|
||||||
|
@ -630,7 +630,7 @@ local function process_function(fn)
|
|||||||
local seterr = ''
|
local seterr = ''
|
||||||
if string.match(param_type, '^KeyDict_') then
|
if string.match(param_type, '^KeyDict_') then
|
||||||
write_shifted_output(output, string.format([[
|
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))
|
%s %s = { 0 }; nlua_pop_keydict(lstate, &%s, %s_get_field, &err_param, &err);]], param_type, cparam, cparam, param_type))
|
||||||
cparam = '&'..cparam
|
cparam = '&'..cparam
|
||||||
errshift = 1 -- free incomplete dict on error
|
errshift = 1 -- free incomplete dict on error
|
||||||
else
|
else
|
||||||
|
@ -813,7 +813,7 @@ String nlua_pop_String(lua_State *lstate, Error *err)
|
|||||||
{
|
{
|
||||||
if (lua_type(lstate, -1) != LUA_TSTRING) {
|
if (lua_type(lstate, -1) != LUA_TSTRING) {
|
||||||
lua_pop(lstate, 1);
|
lua_pop(lstate, 1);
|
||||||
api_set_error(err, kErrorTypeValidation, "Expected lua string");
|
api_set_error(err, kErrorTypeValidation, "Expected Lua string");
|
||||||
return (String) { .size = 0, .data = NULL };
|
return (String) { .size = 0, .data = NULL };
|
||||||
}
|
}
|
||||||
String ret;
|
String ret;
|
||||||
@ -834,7 +834,7 @@ Integer nlua_pop_Integer(lua_State *lstate, Error *err)
|
|||||||
{
|
{
|
||||||
if (lua_type(lstate, -1) != LUA_TNUMBER) {
|
if (lua_type(lstate, -1) != LUA_TNUMBER) {
|
||||||
lua_pop(lstate, 1);
|
lua_pop(lstate, 1);
|
||||||
api_set_error(err, kErrorTypeValidation, "Expected lua number");
|
api_set_error(err, kErrorTypeValidation, "Expected Lua number");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
const lua_Number n = lua_tonumber(lstate, -1);
|
const lua_Number n = lua_tonumber(lstate, -1);
|
||||||
@ -871,7 +871,7 @@ static inline LuaTableProps nlua_check_type(lua_State *const lstate, Error *cons
|
|||||||
{
|
{
|
||||||
if (lua_type(lstate, -1) != LUA_TTABLE) {
|
if (lua_type(lstate, -1) != LUA_TTABLE) {
|
||||||
if (err) {
|
if (err) {
|
||||||
api_set_error(err, kErrorTypeValidation, "Expected lua %s",
|
api_set_error(err, kErrorTypeValidation, "Expected Lua %s",
|
||||||
(type == kObjectTypeFloat) ? "number" : "table");
|
(type == kObjectTypeFloat) ? "number" : "table");
|
||||||
}
|
}
|
||||||
return (LuaTableProps) { .type = kObjectTypeNil };
|
return (LuaTableProps) { .type = kObjectTypeNil };
|
||||||
@ -885,7 +885,7 @@ static inline LuaTableProps nlua_check_type(lua_State *const lstate, Error *cons
|
|||||||
|
|
||||||
if (table_props.type != type) {
|
if (table_props.type != type) {
|
||||||
if (err) {
|
if (err) {
|
||||||
api_set_error(err, kErrorTypeValidation, "Expected %s-like lua table", api_typename(type));
|
api_set_error(err, kErrorTypeValidation, "Expected %s-like Lua table", api_typename(type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1169,7 +1169,7 @@ Object nlua_pop_Object(lua_State *const lstate, bool ref, Error *const err)
|
|||||||
break;
|
break;
|
||||||
case kObjectTypeNil:
|
case kObjectTypeNil:
|
||||||
api_set_error(err, kErrorTypeValidation,
|
api_set_error(err, kErrorTypeValidation,
|
||||||
"Cannot convert given lua table");
|
"Cannot convert given Lua table");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
abort();
|
abort();
|
||||||
@ -1287,10 +1287,10 @@ void nlua_init_types(lua_State *const lstate)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// lua specific variant of api_dict_to_keydict
|
// lua specific variant of api_dict_to_keydict
|
||||||
void nlua_pop_keydict(lua_State *L, void *retval, FieldHashfn hashy, Error *err)
|
void nlua_pop_keydict(lua_State *L, void *retval, FieldHashfn hashy, char **err_opt, Error *err)
|
||||||
{
|
{
|
||||||
if (!lua_istable(L, -1)) {
|
if (!lua_istable(L, -1)) {
|
||||||
api_set_error(err, kErrorTypeValidation, "Expected lua table");
|
api_set_error(err, kErrorTypeValidation, "Expected Lua table");
|
||||||
lua_pop(L, -1);
|
lua_pop(L, -1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1336,6 +1336,7 @@ void nlua_pop_keydict(lua_State *L, void *retval, FieldHashfn hashy, Error *err)
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
if (ERROR_SET(err)) {
|
if (ERROR_SET(err)) {
|
||||||
|
*err_opt = field->str;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user