extmark: move id to dict in nvim_buf_set_extmark

This commit is contained in:
Björn Linse
2020-01-21 14:01:40 +01:00
committed by Thomas Vigouroux
parent 54ce1010e8
commit d3302573ba
2 changed files with 30 additions and 19 deletions

View File

@@ -1274,7 +1274,7 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, Object start,
/// @param opts Optional parameters. Currently not used.
/// @param[out] err Error details, if any
/// @return Id of the created/updated extmark
Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer id,
Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id,
Integer line, Integer col,
Dictionary opts, Error *err)
FUNC_API_SINCE(7)
@@ -1289,11 +1289,6 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer id,
return 0;
}
if (opts.size > 0) {
api_set_error(err, kErrorTypeValidation, "opts dict isn't empty");
return 0;
}
size_t len = 0;
if (line < 0 || line > buf->b_ml.ml_line_count) {
api_set_error(err, kErrorTypeValidation, "line value outside range");
@@ -1309,19 +1304,32 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer id,
return 0;
}
uint64_t id_num;
if (id >= 0) {
id_num = (uint64_t)id;
} else {
api_set_error(err, kErrorTypeValidation, "Invalid mark id");
return 0;
uint64_t id = 0;
for (size_t i = 0; i < opts.size; i++) {
String k = opts.items[i].key;
Object *v = &opts.items[i].value;
if (strequal("id", k.data)) {
if (v->type != kObjectTypeInteger || v->data.integer <= 0) {
api_set_error(err, kErrorTypeValidation,
"id is not a positive integer");
goto error;
}
id = (uint64_t)v->data.integer;
} else {
api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data);
goto error;
}
}
id_num = extmark_set(buf, (uint64_t)ns_id, id_num,
(int)line, (colnr_T)col,
-1, -1, NULL, kExtmarkUndo);
return (Integer)id_num;
id = extmark_set(buf, (uint64_t)ns_id, id,
(int)line, (colnr_T)col, -1, -1, NULL, kExtmarkUndo);
return (Integer)id;
error:
return 0;
}
/// Removes an extmark.