mirror of
https://github.com/neovim/neovim.git
synced 2024-12-31 17:13:26 -07:00
parent
4524053874
commit
5c9860a0a2
@ -225,8 +225,7 @@ for i = 1, #functions do
|
|||||||
end
|
end
|
||||||
output:write('\n')
|
output:write('\n')
|
||||||
output:write('\n if (args.size != '..#fn.parameters..') {')
|
output:write('\n if (args.size != '..#fn.parameters..') {')
|
||||||
output:write('\n snprintf(error->msg, sizeof(error->msg), "Wrong number of arguments: expecting '..#fn.parameters..' but got %zu", args.size);')
|
output:write('\n _api_set_error(error, error->type, "Wrong number of arguments: expecting '..#fn.parameters..' but got %zu", args.size);')
|
||||||
output:write('\n error->set = true;')
|
|
||||||
output:write('\n goto cleanup;')
|
output:write('\n goto cleanup;')
|
||||||
output:write('\n }\n')
|
output:write('\n }\n')
|
||||||
|
|
||||||
@ -251,8 +250,7 @@ for i = 1, #functions do
|
|||||||
output:write('\n '..converted..' = (handle_T)args.items['..(j - 1)..'].data.integer;')
|
output:write('\n '..converted..' = (handle_T)args.items['..(j - 1)..'].data.integer;')
|
||||||
end
|
end
|
||||||
output:write('\n } else {')
|
output:write('\n } else {')
|
||||||
output:write('\n snprintf(error->msg, sizeof(error->msg), "Wrong type for argument '..j..', expecting '..param[1]..'");')
|
output:write('\n _api_set_error(error, error->type, "Wrong type for argument '..j..', expecting '..param[1]..'");')
|
||||||
output:write('\n error->set = true;')
|
|
||||||
output:write('\n goto cleanup;')
|
output:write('\n goto cleanup;')
|
||||||
output:write('\n }\n')
|
output:write('\n }\n')
|
||||||
else
|
else
|
||||||
|
@ -171,7 +171,7 @@ ArrayOf(String) nvim_buf_get_lines(uint64_t channel_id,
|
|||||||
end = normalize_index(buf, end, &oob);
|
end = normalize_index(buf, end, &oob);
|
||||||
|
|
||||||
if (strict_indexing && oob) {
|
if (strict_indexing && oob) {
|
||||||
api_set_error(err, Validation, _("Index out of bounds"));
|
_api_set_error(err, kErrorTypeValidation, _("Index out of bounds"));
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,7 +187,7 @@ ArrayOf(String) nvim_buf_get_lines(uint64_t channel_id,
|
|||||||
int64_t lnum = start + (int64_t)i;
|
int64_t lnum = start + (int64_t)i;
|
||||||
|
|
||||||
if (lnum > LONG_MAX) {
|
if (lnum > LONG_MAX) {
|
||||||
api_set_error(err, Validation, _("Line index is too high"));
|
_api_set_error(err, kErrorTypeValidation, _("Line index is too high"));
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -283,14 +283,14 @@ void nvim_buf_set_lines(uint64_t channel_id,
|
|||||||
end = normalize_index(buf, end, &oob);
|
end = normalize_index(buf, end, &oob);
|
||||||
|
|
||||||
if (strict_indexing && oob) {
|
if (strict_indexing && oob) {
|
||||||
api_set_error(err, Validation, _("Index out of bounds"));
|
_api_set_error(err, kErrorTypeValidation, _("Index out of bounds"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (start > end) {
|
if (start > end) {
|
||||||
api_set_error(err,
|
_api_set_error(err,
|
||||||
Validation,
|
kErrorTypeValidation,
|
||||||
_("Argument \"start\" is higher than \"end\""));
|
_("Argument \"start\" is higher than \"end\""));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -304,8 +304,8 @@ void nvim_buf_set_lines(uint64_t channel_id,
|
|||||||
|
|
||||||
for (size_t i = 0; i < new_len; i++) {
|
for (size_t i = 0; i < new_len; i++) {
|
||||||
if (replacement.items[i].type != kObjectTypeString) {
|
if (replacement.items[i].type != kObjectTypeString) {
|
||||||
api_set_error(err,
|
_api_set_error(err,
|
||||||
Validation,
|
kErrorTypeValidation,
|
||||||
_("All items in the replacement array must be strings"));
|
_("All items in the replacement array must be strings"));
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
@ -317,7 +317,7 @@ void nvim_buf_set_lines(uint64_t channel_id,
|
|||||||
lines[i] = xmallocz(l.size);
|
lines[i] = xmallocz(l.size);
|
||||||
for (size_t j = 0; j < l.size; j++) {
|
for (size_t j = 0; j < l.size; j++) {
|
||||||
if (l.data[j] == '\n' && channel_id != INTERNAL_CALL) {
|
if (l.data[j] == '\n' && channel_id != INTERNAL_CALL) {
|
||||||
api_set_error(err, Exception, _("string cannot contain newlines"));
|
_api_set_error(err, kErrorTypeException, _("string cannot contain newlines"));
|
||||||
new_len = i + 1;
|
new_len = i + 1;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
@ -330,7 +330,7 @@ void nvim_buf_set_lines(uint64_t channel_id,
|
|||||||
switch_to_win_for_buf(buf, &save_curwin, &save_curtab, &save_curbuf);
|
switch_to_win_for_buf(buf, &save_curwin, &save_curtab, &save_curbuf);
|
||||||
|
|
||||||
if (u_save((linenr_T)(start - 1), (linenr_T)end) == FAIL) {
|
if (u_save((linenr_T)(start - 1), (linenr_T)end) == FAIL) {
|
||||||
api_set_error(err, Exception, _("Failed to save undo information"));
|
_api_set_error(err, kErrorTypeException, _("Failed to save undo information"));
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -340,7 +340,7 @@ void nvim_buf_set_lines(uint64_t channel_id,
|
|||||||
size_t to_delete = (new_len < old_len) ? (size_t)(old_len - new_len) : 0;
|
size_t to_delete = (new_len < old_len) ? (size_t)(old_len - new_len) : 0;
|
||||||
for (size_t i = 0; i < to_delete; i++) {
|
for (size_t i = 0; i < to_delete; i++) {
|
||||||
if (ml_delete((linenr_T)start, false) == FAIL) {
|
if (ml_delete((linenr_T)start, false) == FAIL) {
|
||||||
api_set_error(err, Exception, _("Failed to delete line"));
|
_api_set_error(err, kErrorTypeException, _("Failed to delete line"));
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -357,12 +357,12 @@ void nvim_buf_set_lines(uint64_t channel_id,
|
|||||||
int64_t lnum = start + (int64_t)i;
|
int64_t lnum = start + (int64_t)i;
|
||||||
|
|
||||||
if (lnum > LONG_MAX) {
|
if (lnum > LONG_MAX) {
|
||||||
api_set_error(err, Validation, _("Index value is too high"));
|
_api_set_error(err, kErrorTypeValidation, _("Index value is too high"));
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ml_replace((linenr_T)lnum, (char_u *)lines[i], false) == FAIL) {
|
if (ml_replace((linenr_T)lnum, (char_u *)lines[i], false) == FAIL) {
|
||||||
api_set_error(err, Exception, _("Failed to replace line"));
|
_api_set_error(err, kErrorTypeException, _("Failed to replace line"));
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
// Mark lines that haven't been passed to the buffer as they need
|
// Mark lines that haven't been passed to the buffer as they need
|
||||||
@ -375,12 +375,12 @@ void nvim_buf_set_lines(uint64_t channel_id,
|
|||||||
int64_t lnum = start + (int64_t)i - 1;
|
int64_t lnum = start + (int64_t)i - 1;
|
||||||
|
|
||||||
if (lnum > LONG_MAX) {
|
if (lnum > LONG_MAX) {
|
||||||
api_set_error(err, Validation, _("Index value is too high"));
|
_api_set_error(err, kErrorTypeValidation, _("Index value is too high"));
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ml_append((linenr_T)lnum, (char_u *)lines[i], 0, false) == FAIL) {
|
if (ml_append((linenr_T)lnum, (char_u *)lines[i], 0, false) == FAIL) {
|
||||||
api_set_error(err, Exception, _("Failed to insert line"));
|
_api_set_error(err, kErrorTypeException, _("Failed to insert line"));
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -627,7 +627,7 @@ void nvim_buf_set_name(Buffer buffer, String name, Error *err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ren_ret == FAIL) {
|
if (ren_ret == FAIL) {
|
||||||
api_set_error(err, Exception, _("Failed to rename buffer"));
|
_api_set_error(err, kErrorTypeException, _("Failed to rename buffer"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -639,7 +639,9 @@ Boolean nvim_buf_is_valid(Buffer buffer)
|
|||||||
FUNC_API_SINCE(1)
|
FUNC_API_SINCE(1)
|
||||||
{
|
{
|
||||||
Error stub = ERROR_INIT;
|
Error stub = ERROR_INIT;
|
||||||
return find_buffer_by_handle(buffer, &stub) != NULL;
|
Boolean ret = find_buffer_by_handle(buffer, &stub) != NULL;
|
||||||
|
xfree(stub.msg);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Inserts a sequence of lines to a buffer at a certain index
|
/// Inserts a sequence of lines to a buffer at a certain index
|
||||||
@ -678,7 +680,7 @@ ArrayOf(Integer, 2) nvim_buf_get_mark(Buffer buffer, String name, Error *err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (name.size != 1) {
|
if (name.size != 1) {
|
||||||
api_set_error(err, Validation, _("Mark name must be a single character"));
|
_api_set_error(err, kErrorTypeValidation, _("Mark name must be a single character"));
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -696,7 +698,7 @@ ArrayOf(Integer, 2) nvim_buf_get_mark(Buffer buffer, String name, Error *err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (posp == NULL) {
|
if (posp == NULL) {
|
||||||
api_set_error(err, Validation, _("Invalid mark name"));
|
_api_set_error(err, kErrorTypeValidation, _("Invalid mark name"));
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -751,11 +753,11 @@ Integer nvim_buf_add_highlight(Buffer buffer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (line < 0 || line >= MAXLNUM) {
|
if (line < 0 || line >= MAXLNUM) {
|
||||||
api_set_error(err, Validation, _("Line number outside range"));
|
_api_set_error(err, kErrorTypeValidation, _("Line number outside range"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (col_start < 0 || col_start > MAXCOL) {
|
if (col_start < 0 || col_start > MAXCOL) {
|
||||||
api_set_error(err, Validation, _("Column value outside range"));
|
_api_set_error(err, kErrorTypeValidation, _("Column value outside range"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (col_end < 0 || col_end > MAXCOL) {
|
if (col_end < 0 || col_end > MAXCOL) {
|
||||||
@ -792,7 +794,7 @@ void nvim_buf_clear_highlight(Buffer buffer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (line_start < 0 || line_start >= MAXLNUM) {
|
if (line_start < 0 || line_start >= MAXLNUM) {
|
||||||
api_set_error(err, Validation, _("Line number outside range"));
|
_api_set_error(err, kErrorTypeValidation, _("Line number outside range"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (line_end < 0 || line_end > MAXLNUM) {
|
if (line_end < 0 || line_end > MAXLNUM) {
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#define ARRAY_DICT_INIT {.size = 0, .capacity = 0, .items = NULL}
|
#define ARRAY_DICT_INIT {.size = 0, .capacity = 0, .items = NULL}
|
||||||
#define STRING_INIT {.data = NULL, .size = 0}
|
#define STRING_INIT {.data = NULL, .size = 0}
|
||||||
#define OBJECT_INIT { .type = kObjectTypeNil }
|
#define OBJECT_INIT { .type = kObjectTypeNil }
|
||||||
#define ERROR_INIT { .set = false }
|
#define ERROR_INIT { .set = false, .msg = NULL }
|
||||||
#define REMOTE_TYPE(type) typedef handle_T type
|
#define REMOTE_TYPE(type) typedef handle_T type
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
@ -38,7 +38,7 @@ typedef enum {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
ErrorType type;
|
ErrorType type;
|
||||||
char msg[1024];
|
char *msg;
|
||||||
bool set;
|
bool set;
|
||||||
} Error;
|
} Error;
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ bool try_end(Error *err)
|
|||||||
discard_current_exception();
|
discard_current_exception();
|
||||||
}
|
}
|
||||||
|
|
||||||
api_set_error(err, Exception, _("Keyboard interrupt"));
|
_api_set_error(err, kErrorTypeException, _("Keyboard interrupt"));
|
||||||
got_int = false;
|
got_int = false;
|
||||||
} else if (msg_list != NULL && *msg_list != NULL) {
|
} else if (msg_list != NULL && *msg_list != NULL) {
|
||||||
int should_free;
|
int should_free;
|
||||||
@ -69,15 +69,14 @@ bool try_end(Error *err)
|
|||||||
ET_ERROR,
|
ET_ERROR,
|
||||||
NULL,
|
NULL,
|
||||||
&should_free);
|
&should_free);
|
||||||
xstrlcpy(err->msg, msg, sizeof(err->msg));
|
_api_set_error(err, err->type, "%s", msg);
|
||||||
err->set = true;
|
|
||||||
free_global_msglist();
|
free_global_msglist();
|
||||||
|
|
||||||
if (should_free) {
|
if (should_free) {
|
||||||
xfree(msg);
|
xfree(msg);
|
||||||
}
|
}
|
||||||
} else if (did_throw) {
|
} else if (did_throw) {
|
||||||
api_set_error(err, Exception, "%s", current_exception->value);
|
_api_set_error(err, kErrorTypeException, "%s", current_exception->value);
|
||||||
discard_current_exception();
|
discard_current_exception();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +93,7 @@ Object dict_get_value(dict_T *dict, String key, Error *err)
|
|||||||
dictitem_T *const di = tv_dict_find(dict, key.data, (ptrdiff_t)key.size);
|
dictitem_T *const di = tv_dict_find(dict, key.data, (ptrdiff_t)key.size);
|
||||||
|
|
||||||
if (di == NULL) {
|
if (di == NULL) {
|
||||||
api_set_error(err, Validation, _("Key not found"));
|
_api_set_error(err, kErrorTypeValidation, _("Key not found"));
|
||||||
return (Object) OBJECT_INIT;
|
return (Object) OBJECT_INIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,17 +117,17 @@ Object dict_set_var(dict_T *dict, String key, Object value, bool del,
|
|||||||
Object rv = OBJECT_INIT;
|
Object rv = OBJECT_INIT;
|
||||||
|
|
||||||
if (dict->dv_lock) {
|
if (dict->dv_lock) {
|
||||||
api_set_error(err, Exception, _("Dictionary is locked"));
|
_api_set_error(err, kErrorTypeException, _("Dictionary is locked"));
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key.size == 0) {
|
if (key.size == 0) {
|
||||||
api_set_error(err, Validation, _("Empty variable names aren't allowed"));
|
_api_set_error(err, kErrorTypeValidation, _("Empty variable names aren't allowed"));
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key.size > INT_MAX) {
|
if (key.size > INT_MAX) {
|
||||||
api_set_error(err, Validation, _("Key length is too high"));
|
_api_set_error(err, kErrorTypeValidation, _("Key length is too high"));
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,13 +135,13 @@ Object dict_set_var(dict_T *dict, String key, Object value, bool del,
|
|||||||
|
|
||||||
if (di != NULL) {
|
if (di != NULL) {
|
||||||
if (di->di_flags & DI_FLAGS_RO) {
|
if (di->di_flags & DI_FLAGS_RO) {
|
||||||
api_set_error(err, Exception, _("Key is read-only: %s"), key.data);
|
_api_set_error(err, kErrorTypeException, _("Key is read-only: %s"), key.data);
|
||||||
return rv;
|
return rv;
|
||||||
} else if (di->di_flags & DI_FLAGS_FIX) {
|
} else if (di->di_flags & DI_FLAGS_FIX) {
|
||||||
api_set_error(err, Exception, _("Key is fixed: %s"), key.data);
|
_api_set_error(err, kErrorTypeException, _("Key is fixed: %s"), key.data);
|
||||||
return rv;
|
return rv;
|
||||||
} else if (di->di_flags & DI_FLAGS_LOCK) {
|
} else if (di->di_flags & DI_FLAGS_LOCK) {
|
||||||
api_set_error(err, Exception, _("Key is locked: %s"), key.data);
|
_api_set_error(err, kErrorTypeException, _("Key is locked: %s"), key.data);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -151,7 +150,7 @@ Object dict_set_var(dict_T *dict, String key, Object value, bool del,
|
|||||||
// Delete the key
|
// Delete the key
|
||||||
if (di == NULL) {
|
if (di == NULL) {
|
||||||
// Doesn't exist, fail
|
// Doesn't exist, fail
|
||||||
api_set_error(err, Validation, _("Key \"%s\" doesn't exist"), key.data);
|
_api_set_error(err, kErrorTypeValidation, _("Key \"%s\" doesn't exist"), key.data);
|
||||||
} else {
|
} else {
|
||||||
// Return the old value
|
// Return the old value
|
||||||
if (retval) {
|
if (retval) {
|
||||||
@ -203,7 +202,7 @@ Object get_option_from(void *from, int type, String name, Error *err)
|
|||||||
Object rv = OBJECT_INIT;
|
Object rv = OBJECT_INIT;
|
||||||
|
|
||||||
if (name.size == 0) {
|
if (name.size == 0) {
|
||||||
api_set_error(err, Validation, _("Empty option name"));
|
_api_set_error(err, kErrorTypeValidation, _("Empty option name"));
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,8 +213,8 @@ Object get_option_from(void *from, int type, String name, Error *err)
|
|||||||
type, from);
|
type, from);
|
||||||
|
|
||||||
if (!flags) {
|
if (!flags) {
|
||||||
api_set_error(err,
|
_api_set_error(err,
|
||||||
Validation,
|
kErrorTypeValidation,
|
||||||
_("Invalid option name \"%s\""),
|
_("Invalid option name \"%s\""),
|
||||||
name.data);
|
name.data);
|
||||||
return rv;
|
return rv;
|
||||||
@ -233,14 +232,14 @@ Object get_option_from(void *from, int type, String name, Error *err)
|
|||||||
rv.data.string.data = stringval;
|
rv.data.string.data = stringval;
|
||||||
rv.data.string.size = strlen(stringval);
|
rv.data.string.size = strlen(stringval);
|
||||||
} else {
|
} else {
|
||||||
api_set_error(err,
|
_api_set_error(err,
|
||||||
Exception,
|
kErrorTypeException,
|
||||||
_("Unable to get value for option \"%s\""),
|
_("Unable to get value for option \"%s\""),
|
||||||
name.data);
|
name.data);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
api_set_error(err,
|
_api_set_error(err,
|
||||||
Exception,
|
kErrorTypeException,
|
||||||
_("Unknown type for option \"%s\""),
|
_("Unknown type for option \"%s\""),
|
||||||
name.data);
|
name.data);
|
||||||
}
|
}
|
||||||
@ -258,15 +257,15 @@ Object get_option_from(void *from, int type, String name, Error *err)
|
|||||||
void set_option_to(void *to, int type, String name, Object value, Error *err)
|
void set_option_to(void *to, int type, String name, Object value, Error *err)
|
||||||
{
|
{
|
||||||
if (name.size == 0) {
|
if (name.size == 0) {
|
||||||
api_set_error(err, Validation, _("Empty option name"));
|
_api_set_error(err, kErrorTypeValidation, _("Empty option name"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int flags = get_option_value_strict(name.data, NULL, NULL, type, to);
|
int flags = get_option_value_strict(name.data, NULL, NULL, type, to);
|
||||||
|
|
||||||
if (flags == 0) {
|
if (flags == 0) {
|
||||||
api_set_error(err,
|
_api_set_error(err,
|
||||||
Validation,
|
kErrorTypeValidation,
|
||||||
_("Invalid option name \"%s\""),
|
_("Invalid option name \"%s\""),
|
||||||
name.data);
|
name.data);
|
||||||
return;
|
return;
|
||||||
@ -274,14 +273,14 @@ void set_option_to(void *to, int type, String name, Object value, Error *err)
|
|||||||
|
|
||||||
if (value.type == kObjectTypeNil) {
|
if (value.type == kObjectTypeNil) {
|
||||||
if (type == SREQ_GLOBAL) {
|
if (type == SREQ_GLOBAL) {
|
||||||
api_set_error(err,
|
_api_set_error(err,
|
||||||
Exception,
|
kErrorTypeException,
|
||||||
_("Unable to unset option \"%s\""),
|
_("Unable to unset option \"%s\""),
|
||||||
name.data);
|
name.data);
|
||||||
return;
|
return;
|
||||||
} else if (!(flags & SOPT_GLOBAL)) {
|
} else if (!(flags & SOPT_GLOBAL)) {
|
||||||
api_set_error(err,
|
_api_set_error(err,
|
||||||
Exception,
|
kErrorTypeException,
|
||||||
_("Cannot unset option \"%s\" "
|
_("Cannot unset option \"%s\" "
|
||||||
"because it doesn't have a global value"),
|
"because it doesn't have a global value"),
|
||||||
name.data);
|
name.data);
|
||||||
@ -296,8 +295,8 @@ void set_option_to(void *to, int type, String name, Object value, Error *err)
|
|||||||
|
|
||||||
if (flags & SOPT_BOOL) {
|
if (flags & SOPT_BOOL) {
|
||||||
if (value.type != kObjectTypeBoolean) {
|
if (value.type != kObjectTypeBoolean) {
|
||||||
api_set_error(err,
|
_api_set_error(err,
|
||||||
Validation,
|
kErrorTypeValidation,
|
||||||
_("Option \"%s\" requires a boolean value"),
|
_("Option \"%s\" requires a boolean value"),
|
||||||
name.data);
|
name.data);
|
||||||
return;
|
return;
|
||||||
@ -307,16 +306,16 @@ void set_option_to(void *to, int type, String name, Object value, Error *err)
|
|||||||
set_option_value_for(name.data, val, NULL, opt_flags, type, to, err);
|
set_option_value_for(name.data, val, NULL, opt_flags, type, to, err);
|
||||||
} else if (flags & SOPT_NUM) {
|
} else if (flags & SOPT_NUM) {
|
||||||
if (value.type != kObjectTypeInteger) {
|
if (value.type != kObjectTypeInteger) {
|
||||||
api_set_error(err,
|
_api_set_error(err,
|
||||||
Validation,
|
kErrorTypeValidation,
|
||||||
_("Option \"%s\" requires an integer value"),
|
_("Option \"%s\" requires an integer value"),
|
||||||
name.data);
|
name.data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value.data.integer > INT_MAX || value.data.integer < INT_MIN) {
|
if (value.data.integer > INT_MAX || value.data.integer < INT_MIN) {
|
||||||
api_set_error(err,
|
_api_set_error(err,
|
||||||
Validation,
|
kErrorTypeValidation,
|
||||||
_("Value for option \"%s\" is outside range"),
|
_("Value for option \"%s\" is outside range"),
|
||||||
name.data);
|
name.data);
|
||||||
return;
|
return;
|
||||||
@ -326,8 +325,8 @@ void set_option_to(void *to, int type, String name, Object value, Error *err)
|
|||||||
set_option_value_for(name.data, val, NULL, opt_flags, type, to, err);
|
set_option_value_for(name.data, val, NULL, opt_flags, type, to, err);
|
||||||
} else {
|
} else {
|
||||||
if (value.type != kObjectTypeString) {
|
if (value.type != kObjectTypeString) {
|
||||||
api_set_error(err,
|
_api_set_error(err,
|
||||||
Validation,
|
kErrorTypeValidation,
|
||||||
_("Option \"%s\" requires a string value"),
|
_("Option \"%s\" requires a string value"),
|
||||||
name.data);
|
name.data);
|
||||||
return;
|
return;
|
||||||
@ -561,13 +560,13 @@ buf_T *find_buffer_by_handle(Buffer buffer, Error *err)
|
|||||||
buf_T *rv = handle_get_buffer(buffer);
|
buf_T *rv = handle_get_buffer(buffer);
|
||||||
|
|
||||||
if (!rv) {
|
if (!rv) {
|
||||||
api_set_error(err, Validation, _("Invalid buffer id"));
|
_api_set_error(err, kErrorTypeValidation, _("Invalid buffer id"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
win_T * find_window_by_handle(Window window, Error *err)
|
win_T *find_window_by_handle(Window window, Error *err)
|
||||||
{
|
{
|
||||||
if (window == 0) {
|
if (window == 0) {
|
||||||
return curwin;
|
return curwin;
|
||||||
@ -576,13 +575,13 @@ win_T * find_window_by_handle(Window window, Error *err)
|
|||||||
win_T *rv = handle_get_window(window);
|
win_T *rv = handle_get_window(window);
|
||||||
|
|
||||||
if (!rv) {
|
if (!rv) {
|
||||||
api_set_error(err, Validation, _("Invalid window id"));
|
_api_set_error(err, kErrorTypeValidation, _("Invalid window id"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
tabpage_T * find_tab_by_handle(Tabpage tabpage, Error *err)
|
tabpage_T *find_tab_by_handle(Tabpage tabpage, Error *err)
|
||||||
{
|
{
|
||||||
if (tabpage == 0) {
|
if (tabpage == 0) {
|
||||||
return curtab;
|
return curtab;
|
||||||
@ -591,7 +590,7 @@ tabpage_T * find_tab_by_handle(Tabpage tabpage, Error *err)
|
|||||||
tabpage_T *rv = handle_get_tabpage(tabpage);
|
tabpage_T *rv = handle_get_tabpage(tabpage);
|
||||||
|
|
||||||
if (!rv) {
|
if (!rv) {
|
||||||
api_set_error(err, Validation, _("Invalid tabpage id"));
|
_api_set_error(err, kErrorTypeValidation, _("Invalid tabpage id"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
@ -659,7 +658,7 @@ bool object_to_vim(Object obj, typval_T *tv, Error *err)
|
|||||||
case kObjectTypeInteger:
|
case kObjectTypeInteger:
|
||||||
if (obj.data.integer > VARNUMBER_MAX
|
if (obj.data.integer > VARNUMBER_MAX
|
||||||
|| obj.data.integer < VARNUMBER_MIN) {
|
|| obj.data.integer < VARNUMBER_MIN) {
|
||||||
api_set_error(err, Validation, _("Integer value outside range"));
|
_api_set_error(err, kErrorTypeValidation, _("Integer value outside range"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -713,7 +712,7 @@ bool object_to_vim(Object obj, typval_T *tv, Error *err)
|
|||||||
String key = item.key;
|
String key = item.key;
|
||||||
|
|
||||||
if (key.size == 0) {
|
if (key.size == 0) {
|
||||||
api_set_error(err, Validation,
|
_api_set_error(err, kErrorTypeValidation,
|
||||||
_("Empty dictionary keys aren't allowed"));
|
_("Empty dictionary keys aren't allowed"));
|
||||||
// cleanup
|
// cleanup
|
||||||
tv_dict_free(dict);
|
tv_dict_free(dict);
|
||||||
@ -801,6 +800,12 @@ void api_free_dictionary(Dictionary value)
|
|||||||
xfree(value.items);
|
xfree(value.items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void api_free_error(Error *value)
|
||||||
|
{
|
||||||
|
xfree(value->msg);
|
||||||
|
value->msg = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
Dictionary api_metadata(void)
|
Dictionary api_metadata(void)
|
||||||
{
|
{
|
||||||
static Dictionary metadata = ARRAY_DICT_INIT;
|
static Dictionary metadata = ARRAY_DICT_INIT;
|
||||||
@ -926,8 +931,8 @@ static void set_option_value_for(char *key,
|
|||||||
if (try_end(err)) {
|
if (try_end(err)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
api_set_error(err,
|
_api_set_error(err,
|
||||||
Exception,
|
kErrorTypeException,
|
||||||
_("Problem while switching windows"));
|
_("Problem while switching windows"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -965,6 +970,26 @@ static void set_option_value_err(char *key,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
api_set_error(err, Exception, "%s", errmsg);
|
_api_set_error(err, kErrorTypeException, "%s", errmsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _api_set_error(Error *err, ErrorType errType, const char *format, ...)
|
||||||
|
FUNC_ATTR_NONNULL_ALL
|
||||||
|
{
|
||||||
|
va_list args1;
|
||||||
|
va_list args2;
|
||||||
|
va_start(args1, format);
|
||||||
|
va_copy(args2, args1);
|
||||||
|
int len = vsnprintf(NULL, 0, format, args1);
|
||||||
|
va_end(args1);
|
||||||
|
assert(len >= 0);
|
||||||
|
// Limit error message to 1 MB.
|
||||||
|
size_t bufsize = MIN((size_t)len + 1, 1024 * 1024);
|
||||||
|
err->msg = xmalloc(bufsize);
|
||||||
|
vsnprintf(err->msg, bufsize, format, args2);
|
||||||
|
va_end(args2);
|
||||||
|
|
||||||
|
err->set = true;
|
||||||
|
err->type = errType;
|
||||||
|
}
|
||||||
|
@ -8,16 +8,6 @@
|
|||||||
#include "nvim/memory.h"
|
#include "nvim/memory.h"
|
||||||
#include "nvim/lib/kvec.h"
|
#include "nvim/lib/kvec.h"
|
||||||
|
|
||||||
// -V:api_set_error:618
|
|
||||||
#define api_set_error(err, errtype, ...) \
|
|
||||||
do { \
|
|
||||||
snprintf((err)->msg, \
|
|
||||||
sizeof((err)->msg), \
|
|
||||||
__VA_ARGS__); \
|
|
||||||
(err)->set = true; \
|
|
||||||
(err)->type = kErrorType##errtype; \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
#define OBJECT_OBJ(o) o
|
#define OBJECT_OBJ(o) o
|
||||||
|
|
||||||
#define BOOLEAN_OBJ(b) ((Object) { \
|
#define BOOLEAN_OBJ(b) ((Object) { \
|
||||||
|
@ -193,6 +193,8 @@ Boolean nvim_tabpage_is_valid(Tabpage tabpage)
|
|||||||
FUNC_API_SINCE(1)
|
FUNC_API_SINCE(1)
|
||||||
{
|
{
|
||||||
Error stub = ERROR_INIT;
|
Error stub = ERROR_INIT;
|
||||||
return find_tab_by_handle(tabpage, &stub) != NULL;
|
Boolean ret = find_tab_by_handle(tabpage, &stub) != NULL;
|
||||||
|
xfree(stub.msg);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,12 +55,12 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height,
|
|||||||
FUNC_API_SINCE(1) FUNC_API_NOEVAL
|
FUNC_API_SINCE(1) FUNC_API_NOEVAL
|
||||||
{
|
{
|
||||||
if (pmap_has(uint64_t)(connected_uis, channel_id)) {
|
if (pmap_has(uint64_t)(connected_uis, channel_id)) {
|
||||||
api_set_error(err, Exception, _("UI already attached for channel"));
|
_api_set_error(err, kErrorTypeException, _("UI already attached for channel"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (width <= 0 || height <= 0) {
|
if (width <= 0 || height <= 0) {
|
||||||
api_set_error(err, Validation,
|
_api_set_error(err, kErrorTypeValidation,
|
||||||
_("Expected width > 0 and height > 0"));
|
_("Expected width > 0 and height > 0"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -126,7 +126,7 @@ void nvim_ui_detach(uint64_t channel_id, Error *err)
|
|||||||
FUNC_API_SINCE(1) FUNC_API_NOEVAL
|
FUNC_API_SINCE(1) FUNC_API_NOEVAL
|
||||||
{
|
{
|
||||||
if (!pmap_has(uint64_t)(connected_uis, channel_id)) {
|
if (!pmap_has(uint64_t)(connected_uis, channel_id)) {
|
||||||
api_set_error(err, Exception, _("UI is not attached for channel"));
|
_api_set_error(err, kErrorTypeException, _("UI is not attached for channel"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
remote_ui_disconnect(channel_id);
|
remote_ui_disconnect(channel_id);
|
||||||
@ -138,12 +138,12 @@ void nvim_ui_try_resize(uint64_t channel_id, Integer width,
|
|||||||
FUNC_API_SINCE(1) FUNC_API_NOEVAL
|
FUNC_API_SINCE(1) FUNC_API_NOEVAL
|
||||||
{
|
{
|
||||||
if (!pmap_has(uint64_t)(connected_uis, channel_id)) {
|
if (!pmap_has(uint64_t)(connected_uis, channel_id)) {
|
||||||
api_set_error(err, Exception, _("UI is not attached for channel"));
|
_api_set_error(err, kErrorTypeException, _("UI is not attached for channel"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (width <= 0 || height <= 0) {
|
if (width <= 0 || height <= 0) {
|
||||||
api_set_error(err, Validation,
|
_api_set_error(err, kErrorTypeValidation,
|
||||||
_("Expected width > 0 and height > 0"));
|
_("Expected width > 0 and height > 0"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -159,7 +159,7 @@ void nvim_ui_set_option(uint64_t channel_id, String name,
|
|||||||
FUNC_API_SINCE(1) FUNC_API_NOEVAL
|
FUNC_API_SINCE(1) FUNC_API_NOEVAL
|
||||||
{
|
{
|
||||||
if (!pmap_has(uint64_t)(connected_uis, channel_id)) {
|
if (!pmap_has(uint64_t)(connected_uis, channel_id)) {
|
||||||
api_set_error(error, Exception, _("UI is not attached for channel"));
|
_api_set_error(error, kErrorTypeException, _("UI is not attached for channel"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
UI *ui = pmap_get(uint64_t)(connected_uis, channel_id);
|
UI *ui = pmap_get(uint64_t)(connected_uis, channel_id);
|
||||||
@ -173,19 +173,19 @@ void nvim_ui_set_option(uint64_t channel_id, String name,
|
|||||||
static void ui_set_option(UI *ui, String name, Object value, Error *error) {
|
static void ui_set_option(UI *ui, String name, Object value, Error *error) {
|
||||||
if (strcmp(name.data, "rgb") == 0) {
|
if (strcmp(name.data, "rgb") == 0) {
|
||||||
if (value.type != kObjectTypeBoolean) {
|
if (value.type != kObjectTypeBoolean) {
|
||||||
api_set_error(error, Validation, _("rgb must be a Boolean"));
|
_api_set_error(error, kErrorTypeValidation, _("rgb must be a Boolean"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ui->rgb = value.data.boolean;
|
ui->rgb = value.data.boolean;
|
||||||
} else if (strcmp(name.data, "popupmenu_external") == 0) {
|
} else if (strcmp(name.data, "popupmenu_external") == 0) {
|
||||||
if (value.type != kObjectTypeBoolean) {
|
if (value.type != kObjectTypeBoolean) {
|
||||||
api_set_error(error, Validation,
|
_api_set_error(error, kErrorTypeValidation,
|
||||||
_("popupmenu_external must be a Boolean"));
|
_("popupmenu_external must be a Boolean"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ui->pum_external = value.data.boolean;
|
ui->pum_external = value.data.boolean;
|
||||||
} else {
|
} else {
|
||||||
api_set_error(error, Validation, _("No such ui option"));
|
_api_set_error(error, kErrorTypeValidation, _("No such ui option"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,7 +188,7 @@ Object nvim_eval(String expr, Error *err)
|
|||||||
|
|
||||||
typval_T rettv;
|
typval_T rettv;
|
||||||
if (eval0((char_u *)expr.data, &rettv, NULL, true) == FAIL) {
|
if (eval0((char_u *)expr.data, &rettv, NULL, true) == FAIL) {
|
||||||
api_set_error(err, Exception, "Failed to evaluate expression");
|
_api_set_error(err, kErrorTypeException, "Failed to evaluate expression");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!try_end(err)) {
|
if (!try_end(err)) {
|
||||||
@ -214,7 +214,7 @@ Object nvim_call_function(String fname, Array args, Error *err)
|
|||||||
{
|
{
|
||||||
Object rv = OBJECT_INIT;
|
Object rv = OBJECT_INIT;
|
||||||
if (args.size > MAX_FUNC_ARGS) {
|
if (args.size > MAX_FUNC_ARGS) {
|
||||||
api_set_error(err, Validation,
|
_api_set_error(err, kErrorTypeValidation,
|
||||||
_("Function called with too many arguments."));
|
_("Function called with too many arguments."));
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
@ -237,7 +237,7 @@ Object nvim_call_function(String fname, Array args, Error *err)
|
|||||||
curwin->w_cursor.lnum, curwin->w_cursor.lnum, &dummy,
|
curwin->w_cursor.lnum, curwin->w_cursor.lnum, &dummy,
|
||||||
true, NULL, NULL);
|
true, NULL, NULL);
|
||||||
if (r == FAIL) {
|
if (r == FAIL) {
|
||||||
api_set_error(err, Exception, _("Error calling function."));
|
_api_set_error(err, kErrorTypeException, _("Error calling function."));
|
||||||
}
|
}
|
||||||
if (!try_end(err)) {
|
if (!try_end(err)) {
|
||||||
rv = vim_to_object(&rettv);
|
rv = vim_to_object(&rettv);
|
||||||
@ -262,7 +262,7 @@ Integer nvim_strwidth(String str, Error *err)
|
|||||||
FUNC_API_SINCE(1)
|
FUNC_API_SINCE(1)
|
||||||
{
|
{
|
||||||
if (str.size > INT_MAX) {
|
if (str.size > INT_MAX) {
|
||||||
api_set_error(err, Validation, _("String length is too high"));
|
_api_set_error(err, kErrorTypeValidation, _("String length is too high"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -318,7 +318,7 @@ void nvim_set_current_dir(String dir, Error *err)
|
|||||||
FUNC_API_SINCE(1)
|
FUNC_API_SINCE(1)
|
||||||
{
|
{
|
||||||
if (dir.size >= MAXPATHL) {
|
if (dir.size >= MAXPATHL) {
|
||||||
api_set_error(err, Validation, _("Directory string is too long"));
|
_api_set_error(err, kErrorTypeValidation, _("Directory string is too long"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -330,7 +330,7 @@ void nvim_set_current_dir(String dir, Error *err)
|
|||||||
|
|
||||||
if (vim_chdir((char_u *)string, kCdScopeGlobal)) {
|
if (vim_chdir((char_u *)string, kCdScopeGlobal)) {
|
||||||
if (!try_end(err)) {
|
if (!try_end(err)) {
|
||||||
api_set_error(err, Exception, _("Failed to change directory"));
|
_api_set_error(err, kErrorTypeException, _("Failed to change directory"));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -538,8 +538,8 @@ void nvim_set_current_buf(Buffer buffer, Error *err)
|
|||||||
try_start();
|
try_start();
|
||||||
int result = do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, buf->b_fnum, 0);
|
int result = do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, buf->b_fnum, 0);
|
||||||
if (!try_end(err) && result == FAIL) {
|
if (!try_end(err) && result == FAIL) {
|
||||||
api_set_error(err,
|
_api_set_error(err,
|
||||||
Exception,
|
kErrorTypeException,
|
||||||
_("Failed to switch to buffer %d"),
|
_("Failed to switch to buffer %d"),
|
||||||
buffer);
|
buffer);
|
||||||
}
|
}
|
||||||
@ -591,8 +591,8 @@ void nvim_set_current_win(Window window, Error *err)
|
|||||||
try_start();
|
try_start();
|
||||||
goto_tabpage_win(win_find_tabpage(win), win);
|
goto_tabpage_win(win_find_tabpage(win), win);
|
||||||
if (!try_end(err) && win != curwin) {
|
if (!try_end(err) && win != curwin) {
|
||||||
api_set_error(err,
|
_api_set_error(err,
|
||||||
Exception,
|
kErrorTypeException,
|
||||||
_("Failed to switch to window %d"),
|
_("Failed to switch to window %d"),
|
||||||
window);
|
window);
|
||||||
}
|
}
|
||||||
@ -645,8 +645,8 @@ void nvim_set_current_tabpage(Tabpage tabpage, Error *err)
|
|||||||
try_start();
|
try_start();
|
||||||
goto_tabpage_tp(tp, true, true);
|
goto_tabpage_tp(tp, true, true);
|
||||||
if (!try_end(err) && tp != curtab) {
|
if (!try_end(err) && tp != curtab) {
|
||||||
api_set_error(err,
|
_api_set_error(err,
|
||||||
Exception,
|
kErrorTypeException,
|
||||||
_("Failed to switch to tabpage %d"),
|
_("Failed to switch to tabpage %d"),
|
||||||
tabpage);
|
tabpage);
|
||||||
}
|
}
|
||||||
@ -744,30 +744,30 @@ Array nvim_call_atomic(uint64_t channel_id, Array calls, Error *err)
|
|||||||
size_t i; // also used for freeing the variables
|
size_t i; // also used for freeing the variables
|
||||||
for (i = 0; i < calls.size; i++) {
|
for (i = 0; i < calls.size; i++) {
|
||||||
if (calls.items[i].type != kObjectTypeArray) {
|
if (calls.items[i].type != kObjectTypeArray) {
|
||||||
api_set_error(err,
|
_api_set_error(err,
|
||||||
Validation,
|
kErrorTypeValidation,
|
||||||
_("All items in calls array must be arrays"));
|
_("All items in calls array must be arrays"));
|
||||||
goto validation_error;
|
goto validation_error;
|
||||||
}
|
}
|
||||||
Array call = calls.items[i].data.array;
|
Array call = calls.items[i].data.array;
|
||||||
if (call.size != 2) {
|
if (call.size != 2) {
|
||||||
api_set_error(err,
|
_api_set_error(err,
|
||||||
Validation,
|
kErrorTypeValidation,
|
||||||
_("All items in calls array must be arrays of size 2"));
|
_("All items in calls array must be arrays of size 2"));
|
||||||
goto validation_error;
|
goto validation_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (call.items[0].type != kObjectTypeString) {
|
if (call.items[0].type != kObjectTypeString) {
|
||||||
api_set_error(err,
|
_api_set_error(err,
|
||||||
Validation,
|
kErrorTypeValidation,
|
||||||
_("name must be String"));
|
_("name must be String"));
|
||||||
goto validation_error;
|
goto validation_error;
|
||||||
}
|
}
|
||||||
String name = call.items[0].data.string;
|
String name = call.items[0].data.string;
|
||||||
|
|
||||||
if (call.items[1].type != kObjectTypeArray) {
|
if (call.items[1].type != kObjectTypeArray) {
|
||||||
api_set_error(err,
|
_api_set_error(err,
|
||||||
Validation,
|
kErrorTypeValidation,
|
||||||
_("args must be Array"));
|
_("args must be Array"));
|
||||||
goto validation_error;
|
goto validation_error;
|
||||||
}
|
}
|
||||||
@ -794,10 +794,12 @@ Array nvim_call_atomic(uint64_t channel_id, Array calls, Error *err)
|
|||||||
} else {
|
} else {
|
||||||
ADD(rv, NIL);
|
ADD(rv, NIL);
|
||||||
}
|
}
|
||||||
return rv;
|
goto theend;
|
||||||
|
|
||||||
validation_error:
|
validation_error:
|
||||||
api_free_array(results);
|
api_free_array(results);
|
||||||
|
theend:
|
||||||
|
api_free_error(&nested_error);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,8 +64,8 @@ void nvim_win_set_cursor(Window window, ArrayOf(Integer, 2) pos, Error *err)
|
|||||||
|
|
||||||
if (pos.size != 2 || pos.items[0].type != kObjectTypeInteger
|
if (pos.size != 2 || pos.items[0].type != kObjectTypeInteger
|
||||||
|| pos.items[1].type != kObjectTypeInteger) {
|
|| pos.items[1].type != kObjectTypeInteger) {
|
||||||
api_set_error(err,
|
_api_set_error(err,
|
||||||
Validation,
|
kErrorTypeValidation,
|
||||||
_("Argument \"pos\" must be a [row, col] array"));
|
_("Argument \"pos\" must be a [row, col] array"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -78,12 +78,12 @@ void nvim_win_set_cursor(Window window, ArrayOf(Integer, 2) pos, Error *err)
|
|||||||
int64_t col = pos.items[1].data.integer;
|
int64_t col = pos.items[1].data.integer;
|
||||||
|
|
||||||
if (row <= 0 || row > win->w_buffer->b_ml.ml_line_count) {
|
if (row <= 0 || row > win->w_buffer->b_ml.ml_line_count) {
|
||||||
api_set_error(err, Validation, _("Cursor position outside buffer"));
|
_api_set_error(err, kErrorTypeValidation, _("Cursor position outside buffer"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (col > MAXCOL || col < 0) {
|
if (col > MAXCOL || col < 0) {
|
||||||
api_set_error(err, Validation, _("Column value outside range"));
|
_api_set_error(err, kErrorTypeValidation, _("Column value outside range"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ void nvim_win_set_height(Window window, Integer height, Error *err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (height > INT_MAX || height < INT_MIN) {
|
if (height > INT_MAX || height < INT_MIN) {
|
||||||
api_set_error(err, Validation, _("Height value outside range"));
|
_api_set_error(err, kErrorTypeValidation, _("Height value outside range"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,7 +177,7 @@ void nvim_win_set_width(Window window, Integer width, Error *err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (width > INT_MAX || width < INT_MIN) {
|
if (width > INT_MAX || width < INT_MIN) {
|
||||||
api_set_error(err, Validation, _("Width value outside range"));
|
_api_set_error(err, kErrorTypeValidation, _("Width value outside range"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -387,6 +387,8 @@ Boolean nvim_win_is_valid(Window window)
|
|||||||
FUNC_API_SINCE(1)
|
FUNC_API_SINCE(1)
|
||||||
{
|
{
|
||||||
Error stub = ERROR_INIT;
|
Error stub = ERROR_INIT;
|
||||||
return find_window_by_handle(window, &stub) != NULL;
|
Boolean ret = find_window_by_handle(window, &stub) != NULL;
|
||||||
|
xfree(stub.msg);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6524,6 +6524,7 @@ static void api_wrapper(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
end:
|
end:
|
||||||
api_free_array(args);
|
api_free_array(args);
|
||||||
api_free_object(result);
|
api_free_object(result);
|
||||||
|
xfree(err.msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -13794,6 +13795,7 @@ static void f_rpcrequest(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
|
|
||||||
end:
|
end:
|
||||||
api_free_object(result);
|
api_free_object(result);
|
||||||
|
xfree(err.msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// "rpcstart()" function (DEPRECATED)
|
// "rpcstart()" function (DEPRECATED)
|
||||||
@ -16523,7 +16525,7 @@ static void f_termopen(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
curbuf->b_p_swf = false;
|
curbuf->b_p_swf = false;
|
||||||
(void)setfname(curbuf, (char_u *)buf, NULL, true);
|
(void)setfname(curbuf, (char_u *)buf, NULL, true);
|
||||||
// Save the job id and pid in b:terminal_job_{id,pid}
|
// Save the job id and pid in b:terminal_job_{id,pid}
|
||||||
Error err;
|
Error err = ERROR_INIT;
|
||||||
dict_set_var(curbuf->b_vars, cstr_as_string("terminal_job_id"),
|
dict_set_var(curbuf->b_vars, cstr_as_string("terminal_job_id"),
|
||||||
INTEGER_OBJ(rettv->vval.v_number), false, false, &err);
|
INTEGER_OBJ(rettv->vval.v_number), false, false, &err);
|
||||||
dict_set_var(curbuf->b_vars, cstr_as_string("terminal_job_pid"),
|
dict_set_var(curbuf->b_vars, cstr_as_string("terminal_job_pid"),
|
||||||
@ -16532,6 +16534,7 @@ static void f_termopen(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
Terminal *term = terminal_open(topts);
|
Terminal *term = terminal_open(topts);
|
||||||
data->term = term;
|
data->term = term;
|
||||||
data->refcount++;
|
data->refcount++;
|
||||||
|
xfree(err.msg);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,7 @@ Object channel_send_call(uint64_t id,
|
|||||||
Channel *channel = NULL;
|
Channel *channel = NULL;
|
||||||
|
|
||||||
if (!(channel = pmap_get(uint64_t)(channels, id)) || channel->closed) {
|
if (!(channel = pmap_get(uint64_t)(channels, id)) || channel->closed) {
|
||||||
api_set_error(err, Exception, _("Invalid channel \"%" PRIu64 "\""), id);
|
_api_set_error(err, kErrorTypeException, _("Invalid channel \"%" PRIu64 "\""), id);
|
||||||
api_free_array(args);
|
api_free_array(args);
|
||||||
return NIL;
|
return NIL;
|
||||||
}
|
}
|
||||||
@ -212,7 +212,7 @@ Object channel_send_call(uint64_t id,
|
|||||||
|
|
||||||
if (frame.errored) {
|
if (frame.errored) {
|
||||||
if (frame.result.type == kObjectTypeString) {
|
if (frame.result.type == kObjectTypeString) {
|
||||||
api_set_error(err, Exception, "%s", frame.result.data.string.data);
|
_api_set_error(err, kErrorTypeException, "%s", frame.result.data.string.data);
|
||||||
} else if (frame.result.type == kObjectTypeArray) {
|
} else if (frame.result.type == kObjectTypeArray) {
|
||||||
// Should be an error in the form [type, message]
|
// Should be an error in the form [type, message]
|
||||||
Array array = frame.result.data.array;
|
Array array = frame.result.data.array;
|
||||||
@ -220,14 +220,13 @@ Object channel_send_call(uint64_t id,
|
|||||||
&& (array.items[0].data.integer == kErrorTypeException
|
&& (array.items[0].data.integer == kErrorTypeException
|
||||||
|| array.items[0].data.integer == kErrorTypeValidation)
|
|| array.items[0].data.integer == kErrorTypeValidation)
|
||||||
&& array.items[1].type == kObjectTypeString) {
|
&& array.items[1].type == kObjectTypeString) {
|
||||||
err->type = (ErrorType) array.items[0].data.integer;
|
_api_set_error(err, (ErrorType)array.items[0].data.integer, "%s",
|
||||||
xstrlcpy(err->msg, array.items[1].data.string.data, sizeof(err->msg));
|
array.items[1].data.string.data);
|
||||||
err->set = true;
|
|
||||||
} else {
|
} else {
|
||||||
api_set_error(err, Exception, "%s", "unknown error");
|
_api_set_error(err, kErrorTypeException, "%s", "unknown error");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
api_set_error(err, Exception, "%s", "unknown error");
|
_api_set_error(err, kErrorTypeException, "%s", "unknown error");
|
||||||
}
|
}
|
||||||
|
|
||||||
api_free_object(frame.result);
|
api_free_object(frame.result);
|
||||||
@ -412,38 +411,38 @@ static void handle_request(Channel *channel, msgpack_object *request)
|
|||||||
channel->id);
|
channel->id);
|
||||||
call_set_error(channel, buf);
|
call_set_error(channel, buf);
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Retrieve the request handler
|
|
||||||
MsgpackRpcRequestHandler handler;
|
|
||||||
msgpack_object *method = msgpack_rpc_method(request);
|
|
||||||
|
|
||||||
if (method) {
|
|
||||||
handler = msgpack_rpc_get_handler_for(method->via.bin.ptr,
|
|
||||||
method->via.bin.size);
|
|
||||||
} else {
|
} else {
|
||||||
handler.fn = msgpack_rpc_handle_missing_method;
|
// Retrieve the request handler
|
||||||
handler.async = true;
|
MsgpackRpcRequestHandler handler;
|
||||||
}
|
msgpack_object *method = msgpack_rpc_method(request);
|
||||||
|
|
||||||
Array args = ARRAY_DICT_INIT;
|
if (method) {
|
||||||
if (!msgpack_rpc_to_array(msgpack_rpc_args(request), &args)) {
|
handler = msgpack_rpc_get_handler_for(method->via.bin.ptr,
|
||||||
handler.fn = msgpack_rpc_handle_invalid_arguments;
|
method->via.bin.size);
|
||||||
handler.async = true;
|
} else {
|
||||||
}
|
handler.fn = msgpack_rpc_handle_missing_method;
|
||||||
|
handler.async = true;
|
||||||
|
}
|
||||||
|
|
||||||
RequestEvent *event_data = xmalloc(sizeof(RequestEvent));
|
Array args = ARRAY_DICT_INIT;
|
||||||
event_data->channel = channel;
|
if (!msgpack_rpc_to_array(msgpack_rpc_args(request), &args)) {
|
||||||
event_data->handler = handler;
|
handler.fn = msgpack_rpc_handle_invalid_arguments;
|
||||||
event_data->args = args;
|
handler.async = true;
|
||||||
event_data->request_id = request_id;
|
}
|
||||||
incref(channel);
|
|
||||||
if (handler.async) {
|
RequestEvent *event_data = xmalloc(sizeof(RequestEvent));
|
||||||
on_request_event((void **)&event_data);
|
event_data->channel = channel;
|
||||||
} else {
|
event_data->handler = handler;
|
||||||
multiqueue_put(channel->events, on_request_event, 1, event_data);
|
event_data->args = args;
|
||||||
|
event_data->request_id = request_id;
|
||||||
|
incref(channel);
|
||||||
|
if (handler.async) {
|
||||||
|
on_request_event((void **)&event_data);
|
||||||
|
} else {
|
||||||
|
multiqueue_put(channel->events, on_request_event, 1, event_data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
xfree(error.msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void on_request_event(void **argv)
|
static void on_request_event(void **argv)
|
||||||
@ -470,6 +469,7 @@ static void on_request_event(void **argv)
|
|||||||
api_free_array(args);
|
api_free_array(args);
|
||||||
decref(channel);
|
decref(channel);
|
||||||
xfree(e);
|
xfree(e);
|
||||||
|
xfree(error.msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool channel_write(Channel *channel, WBuffer *buffer)
|
static bool channel_write(Channel *channel, WBuffer *buffer)
|
||||||
@ -512,12 +512,13 @@ static bool channel_write(Channel *channel, WBuffer *buffer)
|
|||||||
static void send_error(Channel *channel, uint64_t id, char *err)
|
static void send_error(Channel *channel, uint64_t id, char *err)
|
||||||
{
|
{
|
||||||
Error e = ERROR_INIT;
|
Error e = ERROR_INIT;
|
||||||
api_set_error(&e, Exception, "%s", err);
|
_api_set_error(&e, kErrorTypeException, "%s", err);
|
||||||
channel_write(channel, serialize_response(channel->id,
|
channel_write(channel, serialize_response(channel->id,
|
||||||
id,
|
id,
|
||||||
&e,
|
&e,
|
||||||
NIL,
|
NIL,
|
||||||
&out_buffer));
|
&out_buffer));
|
||||||
|
xfree(e.msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void send_request(Channel *channel,
|
static void send_request(Channel *channel,
|
||||||
|
@ -475,8 +475,7 @@ Object msgpack_rpc_handle_missing_method(uint64_t channel_id,
|
|||||||
Array args,
|
Array args,
|
||||||
Error *error)
|
Error *error)
|
||||||
{
|
{
|
||||||
snprintf(error->msg, sizeof(error->msg), "Invalid method name");
|
_api_set_error(error, error->type, "Invalid method name");
|
||||||
error->set = true;
|
|
||||||
return NIL;
|
return NIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -485,8 +484,7 @@ Object msgpack_rpc_handle_invalid_arguments(uint64_t channel_id,
|
|||||||
Array args,
|
Array args,
|
||||||
Error *error)
|
Error *error)
|
||||||
{
|
{
|
||||||
snprintf(error->msg, sizeof(error->msg), "Invalid method arguments");
|
_api_set_error(error, error->type, "Invalid method arguments");
|
||||||
error->set = true;
|
|
||||||
return NIL;
|
return NIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -572,29 +570,29 @@ void msgpack_rpc_validate(uint64_t *response_id,
|
|||||||
*response_id = NO_RESPONSE;
|
*response_id = NO_RESPONSE;
|
||||||
// Validate the basic structure of the msgpack-rpc payload
|
// Validate the basic structure of the msgpack-rpc payload
|
||||||
if (req->type != MSGPACK_OBJECT_ARRAY) {
|
if (req->type != MSGPACK_OBJECT_ARRAY) {
|
||||||
api_set_error(err, Validation, _("Message is not an array"));
|
_api_set_error(err, kErrorTypeValidation, _("Message is not an array"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req->via.array.size == 0) {
|
if (req->via.array.size == 0) {
|
||||||
api_set_error(err, Validation, _("Message is empty"));
|
_api_set_error(err, kErrorTypeValidation, _("Message is empty"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req->via.array.ptr[0].type != MSGPACK_OBJECT_POSITIVE_INTEGER) {
|
if (req->via.array.ptr[0].type != MSGPACK_OBJECT_POSITIVE_INTEGER) {
|
||||||
api_set_error(err, Validation, _("Message type must be an integer"));
|
_api_set_error(err, kErrorTypeValidation, _("Message type must be an integer"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t type = req->via.array.ptr[0].via.u64;
|
uint64_t type = req->via.array.ptr[0].via.u64;
|
||||||
if (type != kMessageTypeRequest && type != kMessageTypeNotification) {
|
if (type != kMessageTypeRequest && type != kMessageTypeNotification) {
|
||||||
api_set_error(err, Validation, _("Unknown message type"));
|
_api_set_error(err, kErrorTypeValidation, _("Unknown message type"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((type == kMessageTypeRequest && req->via.array.size != 4)
|
if ((type == kMessageTypeRequest && req->via.array.size != 4)
|
||||||
|| (type == kMessageTypeNotification && req->via.array.size != 3)) {
|
|| (type == kMessageTypeNotification && req->via.array.size != 3)) {
|
||||||
api_set_error(err, Validation, _("Request array size should be 4 (request) "
|
_api_set_error(err, kErrorTypeValidation, _("Request array size should be 4 (request) "
|
||||||
"or 3 (notification)"));
|
"or 3 (notification)"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -602,19 +600,19 @@ void msgpack_rpc_validate(uint64_t *response_id,
|
|||||||
if (type == kMessageTypeRequest) {
|
if (type == kMessageTypeRequest) {
|
||||||
msgpack_object *id_obj = msgpack_rpc_msg_id(req);
|
msgpack_object *id_obj = msgpack_rpc_msg_id(req);
|
||||||
if (!id_obj) {
|
if (!id_obj) {
|
||||||
api_set_error(err, Validation, _("ID must be a positive integer"));
|
_api_set_error(err, kErrorTypeValidation, _("ID must be a positive integer"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
*response_id = id_obj->via.u64;
|
*response_id = id_obj->via.u64;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!msgpack_rpc_method(req)) {
|
if (!msgpack_rpc_method(req)) {
|
||||||
api_set_error(err, Validation, _("Method must be a string"));
|
_api_set_error(err, kErrorTypeValidation, _("Method must be a string"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!msgpack_rpc_args(req)) {
|
if (!msgpack_rpc_args(req)) {
|
||||||
api_set_error(err, Validation, _("Parameters must be an array"));
|
_api_set_error(err, kErrorTypeValidation, _("Parameters must be an array"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -633,13 +633,14 @@ static int term_movecursor(VTermPos new, VTermPos old, int visible,
|
|||||||
static void buf_set_term_title(buf_T *buf, char *title)
|
static void buf_set_term_title(buf_T *buf, char *title)
|
||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
Error err;
|
Error err = ERROR_INIT;
|
||||||
dict_set_var(buf->b_vars,
|
dict_set_var(buf->b_vars,
|
||||||
STATIC_CSTR_AS_STRING("term_title"),
|
STATIC_CSTR_AS_STRING("term_title"),
|
||||||
STRING_OBJ(cstr_as_string(title)),
|
STRING_OBJ(cstr_as_string(title)),
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
&err);
|
&err);
|
||||||
|
xfree(err.msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int term_settermprop(VTermProp prop, VTermValue *val, void *data)
|
static int term_settermprop(VTermProp prop, VTermValue *val, void *data)
|
||||||
@ -1220,12 +1221,15 @@ static bool is_focused(Terminal *term)
|
|||||||
|
|
||||||
#define GET_CONFIG_VALUE(k, o) \
|
#define GET_CONFIG_VALUE(k, o) \
|
||||||
do { \
|
do { \
|
||||||
Error err; \
|
Error err = ERROR_INIT; \
|
||||||
/* Only called from terminal_open where curbuf->terminal is the */ \
|
/* Only called from terminal_open where curbuf->terminal is the */ \
|
||||||
/* context */ \
|
/* context */ \
|
||||||
o = dict_get_value(curbuf->b_vars, cstr_as_string(k), &err); \
|
o = dict_get_value(curbuf->b_vars, cstr_as_string(k), &err); \
|
||||||
|
xfree(err.msg); \
|
||||||
if (o.type == kObjectTypeNil) { \
|
if (o.type == kObjectTypeNil) { \
|
||||||
o = dict_get_value(&globvardict, cstr_as_string(k), &err); \
|
Error err2 = ERROR_INIT; \
|
||||||
|
o = dict_get_value(&globvardict, cstr_as_string(k), &err2); \
|
||||||
|
xfree(err2.msg); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
@ -228,7 +228,7 @@ static int get_key_code_timeout(void)
|
|||||||
if (nvim_get_option(cstr_as_string("ttimeout"), &err).data.boolean) {
|
if (nvim_get_option(cstr_as_string("ttimeout"), &err).data.boolean) {
|
||||||
ms = nvim_get_option(cstr_as_string("ttimeoutlen"), &err).data.integer;
|
ms = nvim_get_option(cstr_as_string("ttimeoutlen"), &err).data.integer;
|
||||||
}
|
}
|
||||||
|
xfree(err.msg);
|
||||||
return (int)ms;
|
return (int)ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ local helpers = require('test.functional.helpers')(after_each)
|
|||||||
local eval, command, feed = helpers.eval, helpers.command, helpers.feed
|
local eval, command, feed = helpers.eval, helpers.command, helpers.feed
|
||||||
local eq, clear, insert = helpers.eq, helpers.clear, helpers.insert
|
local eq, clear, insert = helpers.eq, helpers.clear, helpers.insert
|
||||||
local expect, write_file = helpers.expect, helpers.write_file
|
local expect, write_file = helpers.expect, helpers.write_file
|
||||||
|
local feed_command = helpers.feed_command
|
||||||
|
|
||||||
do
|
do
|
||||||
clear()
|
clear()
|
||||||
@ -30,6 +31,15 @@ describe('python3 commands and functions', function()
|
|||||||
eq({100, 0}, eval('g:set_by_python3'))
|
eq({100, 0}, eval('g:set_by_python3'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('does not truncate error message <1 MB', function()
|
||||||
|
-- XXX: Python limits the error name to 200 chars, so this test is
|
||||||
|
-- mostly bogus.
|
||||||
|
local very_long_symbol = string.rep('a', 1200)
|
||||||
|
feed_command(':silent! py3 print('..very_long_symbol..' b)')
|
||||||
|
-- Truncated error message would not contain this (last) line.
|
||||||
|
eq('SyntaxError: invalid syntax', eval('v:errmsg'))
|
||||||
|
end)
|
||||||
|
|
||||||
it('python3_execute with nested commands', function()
|
it('python3_execute with nested commands', function()
|
||||||
command([[python3 vim.command('python3 vim.command("python3 vim.command(\'let set_by_nested_python3 = 555\')")')]])
|
command([[python3 vim.command('python3 vim.command("python3 vim.command(\'let set_by_nested_python3 = 555\')")')]])
|
||||||
eq(555, eval('g:set_by_nested_python3'))
|
eq(555, eval('g:set_by_nested_python3'))
|
||||||
|
Loading…
Reference in New Issue
Block a user