From 76273c7a978404d711ff71f38be3b44275f71f68 Mon Sep 17 00:00:00 2001 From: charliie-dev Date: Sat, 21 Nov 2026 02:05:03 +0800 Subject: [PATCH] fix: skip virtual text for a list that changed after rendering The virtual text is added from a scheduled callback that only checked the line count. When a one-item list was emptied before it ran, the leftover empty line passed that check and placing the extmark failed with "Invalid 'col': out of range". Leave the buffer alone when its lines no longer match what was rendered; a newer render schedules its own update. --- lua/quicker/display.lua | 11 ++++++++++- tests/display_spec.lua | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) 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({