mirror of
https://github.com/neovim/neovim.git
synced 2025-10-07 02:16:31 +00:00
extmark: move id to dict in nvim_buf_set_extmark
This commit is contained in:

committed by
Thomas Vigouroux

parent
54ce1010e8
commit
d3302573ba
@@ -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_num = extmark_set(buf, (uint64_t)ns_id, id_num,
|
||||
(int)line, (colnr_T)col,
|
||||
-1, -1, NULL, kExtmarkUndo);
|
||||
id = (uint64_t)v->data.integer;
|
||||
} else {
|
||||
api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
|
@@ -32,7 +32,10 @@ local function set_extmark(ns_id, id, line, col, opts)
|
||||
if opts == nil then
|
||||
opts = {}
|
||||
end
|
||||
return curbufmeths.set_extmark(ns_id, id, line, col, opts)
|
||||
if id ~= nil and id ~= 0 then
|
||||
opts.id = id
|
||||
end
|
||||
return curbufmeths.set_extmark(ns_id, line, col, opts)
|
||||
end
|
||||
|
||||
local function get_extmarks(ns_id, start, end_, opts)
|
||||
@@ -1357,14 +1360,14 @@ describe('API/extmarks', function()
|
||||
it('can set a mark to other buffer', function()
|
||||
local buf = request('nvim_create_buf', 0, 1)
|
||||
request('nvim_buf_set_lines', buf, 0, -1, 1, {"", ""})
|
||||
local id = bufmeths.set_extmark(buf, ns, 0, 1, 0, {})
|
||||
local id = bufmeths.set_extmark(buf, ns, 1, 0, {})
|
||||
eq({{id, 1, 0}}, bufmeths.get_extmarks(buf, ns, 0, -1, {}))
|
||||
end)
|
||||
|
||||
it('does not crash with append/delete/undo seqence', function()
|
||||
meths.exec([[
|
||||
let ns = nvim_create_namespace('myplugin')
|
||||
call nvim_buf_set_extmark(0, ns, 0, 0, 0, {})
|
||||
call nvim_buf_set_extmark(0, ns, 0, 0, {})
|
||||
call append(0, '')
|
||||
%delete
|
||||
undo]],false)
|
||||
|
Reference in New Issue
Block a user