mirror of
https://github.com/neovim/neovim.git
synced 2025-09-14 15:28:17 +00:00
API: be less breaking in the christmas tree decorations
This commit is contained in:
@@ -1161,11 +1161,13 @@ static Array extmark_to_array(ExtmarkInfo extmark, bool id, bool add_dict)
|
|||||||
/// @param buffer Buffer handle, or 0 for current buffer
|
/// @param buffer Buffer handle, or 0 for current buffer
|
||||||
/// @param ns_id Namespace id from |nvim_create_namespace()|
|
/// @param ns_id Namespace id from |nvim_create_namespace()|
|
||||||
/// @param id Extmark id
|
/// @param id Extmark id
|
||||||
/// @param details Wether to include the details dict
|
/// @param opts Optional parameters. Keys:
|
||||||
|
/// - limit: Maximum number of marks to return
|
||||||
|
/// - details Whether to include the details dict
|
||||||
/// @param[out] err Error details, if any
|
/// @param[out] err Error details, if any
|
||||||
/// @return (row, col) tuple or empty list () if extmark id was absent
|
/// @return (row, col) tuple or empty list () if extmark id was absent
|
||||||
ArrayOf(Integer) nvim_buf_get_extmark_by_id(Buffer buffer, Integer ns_id,
|
ArrayOf(Integer) nvim_buf_get_extmark_by_id(Buffer buffer, Integer ns_id,
|
||||||
Integer id, Boolean details,
|
Integer id, Dictionary opts,
|
||||||
Error *err)
|
Error *err)
|
||||||
FUNC_API_SINCE(7)
|
FUNC_API_SINCE(7)
|
||||||
{
|
{
|
||||||
@@ -1182,6 +1184,26 @@ ArrayOf(Integer) nvim_buf_get_extmark_by_id(Buffer buffer, Integer ns_id,
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool details = false;
|
||||||
|
for (size_t i = 0; i < opts.size; i++) {
|
||||||
|
String k = opts.items[i].key;
|
||||||
|
Object *v = &opts.items[i].value;
|
||||||
|
if (strequal("details", k.data)) {
|
||||||
|
if (v->type == kObjectTypeBoolean) {
|
||||||
|
details = v->data.boolean;
|
||||||
|
} else if (v->type == kObjectTypeInteger) {
|
||||||
|
details = v->data.integer;
|
||||||
|
} else {
|
||||||
|
api_set_error(err, kErrorTypeValidation, "details is not an boolean");
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ExtmarkInfo extmark = extmark_from_id(buf, (uint64_t)ns_id, (uint64_t)id);
|
ExtmarkInfo extmark = extmark_from_id(buf, (uint64_t)ns_id, (uint64_t)id);
|
||||||
if (extmark.row < 0) {
|
if (extmark.row < 0) {
|
||||||
return rv;
|
return rv;
|
||||||
@@ -1229,13 +1251,12 @@ ArrayOf(Integer) nvim_buf_get_extmark_by_id(Buffer buffer, Integer ns_id,
|
|||||||
/// (whose position defines the bound)
|
/// (whose position defines the bound)
|
||||||
/// @param opts Optional parameters. Keys:
|
/// @param opts Optional parameters. Keys:
|
||||||
/// - limit: Maximum number of marks to return
|
/// - limit: Maximum number of marks to return
|
||||||
/// @param details Wether to include the details dict
|
/// - details Whether to include the details dict
|
||||||
/// @param[out] err Error details, if any
|
/// @param[out] err Error details, if any
|
||||||
/// @return List of [extmark_id, row, col] tuples in "traversal order".
|
/// @return List of [extmark_id, row, col] tuples in "traversal order".
|
||||||
Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id,
|
Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id,
|
||||||
Object start, Object end,
|
Object start, Object end,
|
||||||
Dictionary opts, Boolean details,
|
Dictionary opts, Error *err)
|
||||||
Error *err)
|
|
||||||
FUNC_API_SINCE(7)
|
FUNC_API_SINCE(7)
|
||||||
{
|
{
|
||||||
Array rv = ARRAY_DICT_INIT;
|
Array rv = ARRAY_DICT_INIT;
|
||||||
@@ -1249,7 +1270,9 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id,
|
|||||||
api_set_error(err, kErrorTypeValidation, "Invalid ns_id");
|
api_set_error(err, kErrorTypeValidation, "Invalid ns_id");
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer limit = -1;
|
Integer limit = -1;
|
||||||
|
bool details = false;
|
||||||
|
|
||||||
for (size_t i = 0; i < opts.size; i++) {
|
for (size_t i = 0; i < opts.size; i++) {
|
||||||
String k = opts.items[i].key;
|
String k = opts.items[i].key;
|
||||||
@@ -1260,6 +1283,15 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id,
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
limit = v->data.integer;
|
limit = v->data.integer;
|
||||||
|
} else if (strequal("details", k.data)) {
|
||||||
|
if (v->type == kObjectTypeBoolean) {
|
||||||
|
details = v->data.boolean;
|
||||||
|
} else if (v->type == kObjectTypeInteger) {
|
||||||
|
details = v->data.integer;
|
||||||
|
} else {
|
||||||
|
api_set_error(err, kErrorTypeValidation, "details is not an boolean");
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data);
|
api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data);
|
||||||
return rv;
|
return rv;
|
||||||
|
@@ -17,17 +17,6 @@ local function expect(contents)
|
|||||||
return eq(contents, helpers.curbuf_contents())
|
return eq(contents, helpers.curbuf_contents())
|
||||||
end
|
end
|
||||||
|
|
||||||
local function check_undo_redo(ns, mark, sr, sc, er, ec) --s = start, e = end
|
|
||||||
local rv = curbufmeths.get_extmark_by_id(ns, mark, false)
|
|
||||||
eq({er, ec}, rv)
|
|
||||||
feed("u")
|
|
||||||
rv = curbufmeths.get_extmark_by_id(ns, mark, false)
|
|
||||||
eq({sr, sc}, rv)
|
|
||||||
feed("<c-r>")
|
|
||||||
rv = curbufmeths.get_extmark_by_id(ns, mark, false)
|
|
||||||
eq({er, ec}, rv)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function set_extmark(ns_id, id, line, col, opts)
|
local function set_extmark(ns_id, id, line, col, opts)
|
||||||
if opts == nil then
|
if opts == nil then
|
||||||
opts = {}
|
opts = {}
|
||||||
@@ -42,7 +31,25 @@ local function get_extmarks(ns_id, start, end_, opts)
|
|||||||
if opts == nil then
|
if opts == nil then
|
||||||
opts = {}
|
opts = {}
|
||||||
end
|
end
|
||||||
return curbufmeths.get_extmarks(ns_id, start, end_, opts, false)
|
return curbufmeths.get_extmarks(ns_id, start, end_, opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function get_extmark_by_id(ns_id, id, opts)
|
||||||
|
if opts == nil then
|
||||||
|
opts = {}
|
||||||
|
end
|
||||||
|
return curbufmeths.get_extmark_by_id(ns_id, id, opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function check_undo_redo(ns, mark, sr, sc, er, ec) --s = start, e = end
|
||||||
|
local rv = get_extmark_by_id(ns, mark)
|
||||||
|
eq({er, ec}, rv)
|
||||||
|
feed("u")
|
||||||
|
rv = get_extmark_by_id(ns, mark)
|
||||||
|
eq({sr, sc}, rv)
|
||||||
|
feed("<c-r>")
|
||||||
|
rv = get_extmark_by_id(ns, mark)
|
||||||
|
eq({er, ec}, rv)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function batch_set(ns_id, positions)
|
local function batch_set(ns_id, positions)
|
||||||
@@ -96,7 +103,7 @@ describe('API/extmarks', function()
|
|||||||
it('adds, updates and deletes marks', function()
|
it('adds, updates and deletes marks', function()
|
||||||
local rv = set_extmark(ns, marks[1], positions[1][1], positions[1][2])
|
local rv = set_extmark(ns, marks[1], positions[1][1], positions[1][2])
|
||||||
eq(marks[1], rv)
|
eq(marks[1], rv)
|
||||||
rv = curbufmeths.get_extmark_by_id(ns, marks[1], false)
|
rv = get_extmark_by_id(ns, marks[1])
|
||||||
eq({positions[1][1], positions[1][2]}, rv)
|
eq({positions[1][1], positions[1][2]}, rv)
|
||||||
-- Test adding a second mark on same row works
|
-- Test adding a second mark on same row works
|
||||||
rv = set_extmark(ns, marks[2], positions[2][1], positions[2][2])
|
rv = set_extmark(ns, marks[2], positions[2][1], positions[2][2])
|
||||||
@@ -105,14 +112,14 @@ describe('API/extmarks', function()
|
|||||||
-- Test an update, (same pos)
|
-- Test an update, (same pos)
|
||||||
rv = set_extmark(ns, marks[1], positions[1][1], positions[1][2])
|
rv = set_extmark(ns, marks[1], positions[1][1], positions[1][2])
|
||||||
eq(marks[1], rv)
|
eq(marks[1], rv)
|
||||||
rv = curbufmeths.get_extmark_by_id(ns, marks[2], false)
|
rv = get_extmark_by_id(ns, marks[2])
|
||||||
eq({positions[2][1], positions[2][2]}, rv)
|
eq({positions[2][1], positions[2][2]}, rv)
|
||||||
-- Test an update, (new pos)
|
-- Test an update, (new pos)
|
||||||
row = positions[1][1]
|
row = positions[1][1]
|
||||||
col = positions[1][2] + 1
|
col = positions[1][2] + 1
|
||||||
rv = set_extmark(ns, marks[1], row, col)
|
rv = set_extmark(ns, marks[1], row, col)
|
||||||
eq(marks[1], rv)
|
eq(marks[1], rv)
|
||||||
rv = curbufmeths.get_extmark_by_id(ns, marks[1], false)
|
rv = get_extmark_by_id(ns, marks[1])
|
||||||
eq({row, col}, rv)
|
eq({row, col}, rv)
|
||||||
|
|
||||||
-- remove the test marks
|
-- remove the test marks
|
||||||
@@ -435,7 +442,7 @@ describe('API/extmarks', function()
|
|||||||
~ |
|
~ |
|
||||||
|
|
|
|
||||||
]])
|
]])
|
||||||
local rv = curbufmeths.get_extmark_by_id(ns, marks[1], false)
|
local rv = get_extmark_by_id(ns, marks[1])
|
||||||
eq({0, 6}, rv)
|
eq({0, 6}, rv)
|
||||||
check_undo_redo(ns, marks[1], 0, 3, 0, 6)
|
check_undo_redo(ns, marks[1], 0, 3, 0, 6)
|
||||||
end)
|
end)
|
||||||
@@ -909,9 +916,9 @@ describe('API/extmarks', function()
|
|||||||
-- Set the mark before the cursor, should stay there
|
-- Set the mark before the cursor, should stay there
|
||||||
set_extmark(ns, marks[2], 0, 10)
|
set_extmark(ns, marks[2], 0, 10)
|
||||||
feed("i<cr><esc>")
|
feed("i<cr><esc>")
|
||||||
local rv = curbufmeths.get_extmark_by_id(ns, marks[1], false)
|
local rv = get_extmark_by_id(ns, marks[1])
|
||||||
eq({1, 3}, rv)
|
eq({1, 3}, rv)
|
||||||
rv = curbufmeths.get_extmark_by_id(ns, marks[2], false)
|
rv = get_extmark_by_id(ns, marks[2])
|
||||||
eq({0, 10}, rv)
|
eq({0, 10}, rv)
|
||||||
check_undo_redo(ns, marks[1], 0, 12, 1, 3)
|
check_undo_redo(ns, marks[1], 0, 12, 1, 3)
|
||||||
end)
|
end)
|
||||||
@@ -924,12 +931,12 @@ describe('API/extmarks', function()
|
|||||||
feed("0iint <esc>A {<cr><esc>0i1M1<esc>")
|
feed("0iint <esc>A {<cr><esc>0i1M1<esc>")
|
||||||
set_extmark(ns, marks[1], 1, 1)
|
set_extmark(ns, marks[1], 1, 1)
|
||||||
feed("0i<c-f><esc>")
|
feed("0i<c-f><esc>")
|
||||||
local rv = curbufmeths.get_extmark_by_id(ns, marks[1], false)
|
local rv = get_extmark_by_id(ns, marks[1])
|
||||||
eq({1, 3}, rv)
|
eq({1, 3}, rv)
|
||||||
check_undo_redo(ns, marks[1], 1, 1, 1, 3)
|
check_undo_redo(ns, marks[1], 1, 1, 1, 3)
|
||||||
-- now check when cursor at eol
|
-- now check when cursor at eol
|
||||||
feed("uA<c-f><esc>")
|
feed("uA<c-f><esc>")
|
||||||
rv = curbufmeths.get_extmark_by_id(ns, marks[1], false)
|
rv = get_extmark_by_id(ns, marks[1])
|
||||||
eq({1, 3}, rv)
|
eq({1, 3}, rv)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -940,12 +947,12 @@ describe('API/extmarks', function()
|
|||||||
feed("0i<tab><esc>")
|
feed("0i<tab><esc>")
|
||||||
set_extmark(ns, marks[1], 0, 3)
|
set_extmark(ns, marks[1], 0, 3)
|
||||||
feed("bi<c-d><esc>")
|
feed("bi<c-d><esc>")
|
||||||
local rv = curbufmeths.get_extmark_by_id(ns, marks[1], false)
|
local rv = get_extmark_by_id(ns, marks[1])
|
||||||
eq({0, 1}, rv)
|
eq({0, 1}, rv)
|
||||||
check_undo_redo(ns, marks[1], 0, 3, 0, 1)
|
check_undo_redo(ns, marks[1], 0, 3, 0, 1)
|
||||||
-- check when cursor at eol
|
-- check when cursor at eol
|
||||||
feed("uA<c-d><esc>")
|
feed("uA<c-d><esc>")
|
||||||
rv = curbufmeths.get_extmark_by_id(ns, marks[1], false)
|
rv = get_extmark_by_id(ns, marks[1])
|
||||||
eq({0, 1}, rv)
|
eq({0, 1}, rv)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -1075,7 +1082,7 @@ describe('API/extmarks', function()
|
|||||||
check_undo_redo(ns, marks[5], 2, 0, 3, 0)
|
check_undo_redo(ns, marks[5], 2, 0, 3, 0)
|
||||||
feed('u')
|
feed('u')
|
||||||
feed([[:1,2s:3:\rxx<cr>]])
|
feed([[:1,2s:3:\rxx<cr>]])
|
||||||
eq({1, 3}, curbufmeths.get_extmark_by_id(ns, marks[3], false))
|
eq({1, 3}, get_extmark_by_id(ns, marks[3]))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('substitions over multiple lines with replace in substition', function()
|
it('substitions over multiple lines with replace in substition', function()
|
||||||
@@ -1314,16 +1321,16 @@ describe('API/extmarks', function()
|
|||||||
eq("Invalid ns_id", pcall_err(set_extmark, ns_invalid, marks[1], positions[1][1], positions[1][2]))
|
eq("Invalid ns_id", pcall_err(set_extmark, ns_invalid, marks[1], positions[1][1], positions[1][2]))
|
||||||
eq("Invalid ns_id", pcall_err(curbufmeths.del_extmark, ns_invalid, marks[1]))
|
eq("Invalid ns_id", pcall_err(curbufmeths.del_extmark, ns_invalid, marks[1]))
|
||||||
eq("Invalid ns_id", pcall_err(get_extmarks, ns_invalid, positions[1], positions[2]))
|
eq("Invalid ns_id", pcall_err(get_extmarks, ns_invalid, positions[1], positions[2]))
|
||||||
eq("Invalid ns_id", pcall_err(curbufmeths.get_extmark_by_id, ns_invalid, marks[1], false))
|
eq("Invalid ns_id", pcall_err(get_extmark_by_id, ns_invalid, marks[1]))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('when col = line-length, set the mark on eol', function()
|
it('when col = line-length, set the mark on eol', function()
|
||||||
set_extmark(ns, marks[1], 0, -1)
|
set_extmark(ns, marks[1], 0, -1)
|
||||||
local rv = curbufmeths.get_extmark_by_id(ns, marks[1], false)
|
local rv = get_extmark_by_id(ns, marks[1])
|
||||||
eq({0, init_text:len()}, rv)
|
eq({0, init_text:len()}, rv)
|
||||||
-- Test another
|
-- Test another
|
||||||
set_extmark(ns, marks[1], 0, -1)
|
set_extmark(ns, marks[1], 0, -1)
|
||||||
rv = curbufmeths.get_extmark_by_id(ns, marks[1], false)
|
rv = get_extmark_by_id(ns, marks[1])
|
||||||
eq({0, init_text:len()}, rv)
|
eq({0, init_text:len()}, rv)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -1336,7 +1343,7 @@ describe('API/extmarks', function()
|
|||||||
local invalid_col = init_text:len() + 1
|
local invalid_col = init_text:len() + 1
|
||||||
local invalid_lnum = 3
|
local invalid_lnum = 3
|
||||||
eq('line value outside range', pcall_err(set_extmark, ns, marks[1], invalid_lnum, invalid_col))
|
eq('line value outside range', pcall_err(set_extmark, ns, marks[1], invalid_lnum, invalid_col))
|
||||||
eq({}, curbufmeths.get_extmark_by_id(ns, marks[1], false))
|
eq({}, get_extmark_by_id(ns, marks[1]))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('bug from check_col in extmark_set', function()
|
it('bug from check_col in extmark_set', function()
|
||||||
@@ -1361,7 +1368,7 @@ describe('API/extmarks', function()
|
|||||||
local buf = request('nvim_create_buf', 0, 1)
|
local buf = request('nvim_create_buf', 0, 1)
|
||||||
request('nvim_buf_set_lines', buf, 0, -1, 1, {"", ""})
|
request('nvim_buf_set_lines', buf, 0, -1, 1, {"", ""})
|
||||||
local id = bufmeths.set_extmark(buf, ns, 1, 0, {})
|
local id = bufmeths.set_extmark(buf, ns, 1, 0, {})
|
||||||
eq({{id, 1, 0}}, bufmeths.get_extmarks(buf, ns, 0, -1, {}, false))
|
eq({{id, 1, 0}}, bufmeths.get_extmarks(buf, ns, 0, -1, {}))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('does not crash with append/delete/undo seqence', function()
|
it('does not crash with append/delete/undo seqence', function()
|
||||||
|
@@ -699,14 +699,14 @@ describe('Buffer highlighting', function()
|
|||||||
-- TODO: only a virtual text from the same ns curretly overrides
|
-- TODO: only a virtual text from the same ns curretly overrides
|
||||||
-- an existing virtual text. We might add a prioritation system.
|
-- an existing virtual text. We might add a prioritation system.
|
||||||
set_virtual_text(id1, 0, s1, {})
|
set_virtual_text(id1, 0, s1, {})
|
||||||
eq({{1, 0, 0, {virt_text = s1}}}, get_extmarks(id1, {0,0}, {0, -1}, {}, true))
|
eq({{1, 0, 0, {virt_text = s1}}}, get_extmarks(id1, {0,0}, {0, -1}, {details=true}))
|
||||||
|
|
||||||
-- TODO: is this really valid? shouldn't the max be line_count()-1?
|
-- TODO: is this really valid? shouldn't the max be line_count()-1?
|
||||||
local lastline = line_count()
|
local lastline = line_count()
|
||||||
set_virtual_text(id1, line_count(), s2, {})
|
set_virtual_text(id1, line_count(), s2, {})
|
||||||
eq({{3, lastline, 0, {virt_text = s2}}}, get_extmarks(id1, {lastline,0}, {lastline, -1}, {}, true))
|
eq({{3, lastline, 0, {virt_text = s2}}}, get_extmarks(id1, {lastline,0}, {lastline, -1}, {details=true}))
|
||||||
|
|
||||||
eq({}, get_extmarks(id1, {lastline+9000,0}, {lastline+9000, -1}, {}, false))
|
eq({}, get_extmarks(id1, {lastline+9000,0}, {lastline+9000, -1}, {}))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('is not highlighted by visual selection', function()
|
it('is not highlighted by visual selection', function()
|
||||||
|
Reference in New Issue
Block a user