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 --- test/functional/api/extmark_spec.lua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index 9ea35e50a2..4bdff1a768 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -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) -- cgit From 49f5b57587ececf37415c64de6224e09baa80f48 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Tue, 21 Jan 2020 15:26:55 +0100 Subject: decor: sketch new decorations API return decorations back lol no nvim_buf_get_virtual_text share decorations that are hl only to avoid alloc avalanche --- test/functional/api/extmark_spec.lua | 40 ++++++++++++++++++------------------ test/functional/ui/bufhl_spec.lua | 12 ++++++----- 2 files changed, 27 insertions(+), 25 deletions(-) (limited to 'test') diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index 4bdff1a768..602f879ae8 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -18,13 +18,13 @@ local function expect(contents) 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) + local rv = curbufmeths.get_extmark_by_id(ns, mark, false) eq({er, ec}, rv) feed("u") - rv = curbufmeths.get_extmark_by_id(ns, mark) + rv = curbufmeths.get_extmark_by_id(ns, mark, false) eq({sr, sc}, rv) feed("") - rv = curbufmeths.get_extmark_by_id(ns, mark) + rv = curbufmeths.get_extmark_by_id(ns, mark, false) eq({er, ec}, rv) end @@ -42,7 +42,7 @@ local function get_extmarks(ns_id, start, end_, opts) if opts == nil then opts = {} end - return curbufmeths.get_extmarks(ns_id, start, end_, opts) + return curbufmeths.get_extmarks(ns_id, start, end_, opts, false) end local function batch_set(ns_id, positions) @@ -96,7 +96,7 @@ describe('API/extmarks', function() it('adds, updates and deletes marks', function() local rv = set_extmark(ns, marks[1], positions[1][1], positions[1][2]) eq(marks[1], rv) - rv = curbufmeths.get_extmark_by_id(ns, marks[1]) + rv = curbufmeths.get_extmark_by_id(ns, marks[1], false) eq({positions[1][1], positions[1][2]}, rv) -- Test adding a second mark on same row works rv = set_extmark(ns, marks[2], positions[2][1], positions[2][2]) @@ -105,14 +105,14 @@ describe('API/extmarks', function() -- Test an update, (same pos) rv = set_extmark(ns, marks[1], positions[1][1], positions[1][2]) eq(marks[1], rv) - rv = curbufmeths.get_extmark_by_id(ns, marks[2]) + rv = curbufmeths.get_extmark_by_id(ns, marks[2], false) eq({positions[2][1], positions[2][2]}, rv) -- Test an update, (new pos) row = positions[1][1] col = positions[1][2] + 1 rv = set_extmark(ns, marks[1], row, col) eq(marks[1], rv) - rv = curbufmeths.get_extmark_by_id(ns, marks[1]) + rv = curbufmeths.get_extmark_by_id(ns, marks[1], false) eq({row, col}, rv) -- remove the test marks @@ -435,7 +435,7 @@ describe('API/extmarks', function() ~ | | ]]) - local rv = curbufmeths.get_extmark_by_id(ns, marks[1]) + local rv = curbufmeths.get_extmark_by_id(ns, marks[1], false) eq({0, 6}, rv) check_undo_redo(ns, marks[1], 0, 3, 0, 6) end) @@ -909,9 +909,9 @@ describe('API/extmarks', function() -- Set the mark before the cursor, should stay there set_extmark(ns, marks[2], 0, 10) feed("i") - local rv = curbufmeths.get_extmark_by_id(ns, marks[1]) + local rv = curbufmeths.get_extmark_by_id(ns, marks[1], false) eq({1, 3}, rv) - rv = curbufmeths.get_extmark_by_id(ns, marks[2]) + rv = curbufmeths.get_extmark_by_id(ns, marks[2], false) eq({0, 10}, rv) check_undo_redo(ns, marks[1], 0, 12, 1, 3) end) @@ -924,12 +924,12 @@ describe('API/extmarks', function() feed("0iint A {0i1M1") set_extmark(ns, marks[1], 1, 1) feed("0i") - local rv = curbufmeths.get_extmark_by_id(ns, marks[1]) + local rv = curbufmeths.get_extmark_by_id(ns, marks[1], false) eq({1, 3}, rv) check_undo_redo(ns, marks[1], 1, 1, 1, 3) -- now check when cursor at eol feed("uA") - rv = curbufmeths.get_extmark_by_id(ns, marks[1]) + rv = curbufmeths.get_extmark_by_id(ns, marks[1], false) eq({1, 3}, rv) end) @@ -940,12 +940,12 @@ describe('API/extmarks', function() feed("0i") set_extmark(ns, marks[1], 0, 3) feed("bi") - local rv = curbufmeths.get_extmark_by_id(ns, marks[1]) + local rv = curbufmeths.get_extmark_by_id(ns, marks[1], false) eq({0, 1}, rv) check_undo_redo(ns, marks[1], 0, 3, 0, 1) -- check when cursor at eol feed("uA") - rv = curbufmeths.get_extmark_by_id(ns, marks[1]) + rv = curbufmeths.get_extmark_by_id(ns, marks[1], false) eq({0, 1}, rv) end) @@ -1075,7 +1075,7 @@ describe('API/extmarks', function() check_undo_redo(ns, marks[5], 2, 0, 3, 0) feed('u') feed([[:1,2s:3:\rxx]]) - eq({1, 3}, curbufmeths.get_extmark_by_id(ns, marks[3])) + eq({1, 3}, curbufmeths.get_extmark_by_id(ns, marks[3], false)) end) it('substitions over multiple lines with replace in substition', function() @@ -1314,16 +1314,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(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(curbufmeths.get_extmark_by_id, ns_invalid, marks[1])) + eq("Invalid ns_id", pcall_err(curbufmeths.get_extmark_by_id, ns_invalid, marks[1], false)) end) it('when col = line-length, set the mark on eol', function() set_extmark(ns, marks[1], 0, -1) - local rv = curbufmeths.get_extmark_by_id(ns, marks[1]) + local rv = curbufmeths.get_extmark_by_id(ns, marks[1], false) eq({0, init_text:len()}, rv) -- Test another set_extmark(ns, marks[1], 0, -1) - rv = curbufmeths.get_extmark_by_id(ns, marks[1]) + rv = curbufmeths.get_extmark_by_id(ns, marks[1], false) eq({0, init_text:len()}, rv) end) @@ -1336,7 +1336,7 @@ describe('API/extmarks', function() local invalid_col = init_text:len() + 1 local invalid_lnum = 3 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])) + eq({}, curbufmeths.get_extmark_by_id(ns, marks[1], false)) end) it('bug from check_col in extmark_set', function() @@ -1361,7 +1361,7 @@ describe('API/extmarks', 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, 1, 0, {}) - eq({{id, 1, 0}}, bufmeths.get_extmarks(buf, ns, 0, -1, {})) + eq({{id, 1, 0}}, bufmeths.get_extmarks(buf, ns, 0, -1, {}, false)) end) it('does not crash with append/delete/undo seqence', function() diff --git a/test/functional/ui/bufhl_spec.lua b/test/functional/ui/bufhl_spec.lua index 3cb592c714..0262a5b59b 100644 --- a/test/functional/ui/bufhl_spec.lua +++ b/test/functional/ui/bufhl_spec.lua @@ -690,7 +690,7 @@ describe('Buffer highlighting', function() end) it('can be retrieved', function() - local get_virtual_text = curbufmeths.get_virtual_text + local get_extmarks = curbufmeths.get_extmarks local line_count = curbufmeths.line_count local s1 = {{'Köttbullar', 'Comment'}, {'Kräuterbutter'}} @@ -699,12 +699,14 @@ describe('Buffer highlighting', function() -- TODO: only a virtual text from the same ns curretly overrides -- an existing virtual text. We might add a prioritation system. set_virtual_text(id1, 0, s1, {}) - eq(s1, get_virtual_text(0)) + eq({{1, 0, 0, {virt_text = s1}}}, get_extmarks(id1, {0,0}, {0, -1}, {}, true)) - set_virtual_text(-1, line_count(), s2, {}) - eq(s2, get_virtual_text(line_count())) + -- TODO: is this really valid? shouldn't the max be line_count()-1? + local lastline = line_count() + set_virtual_text(id1, line_count(), s2, {}) + eq({{3, lastline, 0, {virt_text = s2}}}, get_extmarks(id1, {lastline,0}, {lastline, -1}, {}, true)) - eq({}, get_virtual_text(line_count() + 9000)) + eq({}, get_extmarks(id1, {lastline+9000,0}, {lastline+9000, -1}, {}, false)) end) it('is not highlighted by visual selection', function() -- cgit