From d3302573ba5f117fe7e1316be27321c3d9ffd261 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Tue, 21 Jan 2020 14:01:40 +0100 Subject: extmark: move id to dict in nvim_buf_set_extmark --- src/nvim/api/buffer.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'src/nvim/api/buffer.c') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index e813fc1dd4..462b9ea4f5 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -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. -- cgit