diff --git a/lua/quicker/display.lua b/lua/quicker/display.lua index 2a60b5b..747460a 100644 --- a/lua/quicker/display.lua +++ b/lua/quicker/display.lua @@ -554,6 +554,16 @@ function M.quickfixtextfunc(info) return end + -- The list can change between rendering and this call (for example emptied right after + -- :copen). Then the buffer no longer shows these lines, and a newer render schedules its own + -- call, so leave the buffer alone. + local lines = vim.api.nvim_buf_get_lines(qf_list.qfbufnr, start_idx - 1, -1, false) + for i = 1, #locations do + if lines[i] ~= ret[i] then + return + end + end + local ns = vim.api.nvim_create_namespace("quicker_locations") vim.api.nvim_buf_clear_namespace(qf_list.qfbufnr, ns, start_idx - 1, -1) local header_ns = vim.api.nvim_create_namespace("quicker_headers") @@ -562,7 +572,6 @@ function M.quickfixtextfunc(info) vim.api.nvim_buf_clear_namespace(qf_list.qfbufnr, filename_ns, start_idx - 1, -1) local idmap = {} - local lines = vim.api.nvim_buf_get_lines(qf_list.qfbufnr, start_idx - 1, -1, false) for i, loc in ipairs(locations) do local end_col = lines[i]:find(EM_QUAD, 1, true) or col_width local lnum = start_idx + i - 1 diff --git a/tests/display_spec.lua b/tests/display_spec.lua index c3404ad..b45d4b7 100644 --- a/tests/display_spec.lua +++ b/tests/display_spec.lua @@ -80,6 +80,24 @@ a.describe("display", function() test_util.assert_snapshot(0, "display_minimal_1") end) + a.it("leaves a list alone that changed before its virtual text was added", function() + local bufnr = vim.fn.bufadd(test_util.make_tmp_file("changed.txt", 10)) + vim.v.errmsg = "" + vim.fn.setqflist({ + { + bufnr = bufnr, + text = "text", + lnum = 1, + valid = 1, + }, + }) + vim.cmd.copen() + -- Emptied before the scheduled virtual text runs + vim.fn.setqflist({}) + sleep(50) + assert.equals("", vim.v.errmsg) + end) + a.it("sets signs for diagnostics", function() local bufnr = vim.fn.bufadd(test_util.make_tmp_file("sign_test.txt", 10)) vim.fn.setqflist({