Clear the managed quickfix list with comments #13

Merged
eleith merged 1 commits from fix/clear-owned-quickfix-list into main 2026-11-30 19:52:04 +00:00
5 changed files with 59 additions and 1 deletions

No files matched your search

+1
View File
@@ -15,6 +15,7 @@
identical text remains. Parked comments still reattach on a matching reopen.
- Keep comments with renamed source buffers so export and quickfix use the new name.
- Fall back to filesystem lookup when Git cannot start.
- Remove stale quickfix entries when clearing comments without touching other lists.
## [0.1.0] - 2026-09-30
+1
View File
@@ -198,6 +198,7 @@ function M.clear()
return
end
comments.clear()
require("scratch_comments.list").clear()
notify.info("Cleared comments")
end
+9
View File
@@ -236,6 +236,15 @@ local function jump()
})
end
-- Empty only the list we own, even if another list is current.
function M.clear()
local id = list_id
if id and vim.fn.getqflist({ id = id }).id == id then
-- Replacing items in history redraws the current list; empty lines do not.
vim.fn.setqflist({}, "r", { id = id, lines = {}, efm = "%m" })
end
end
-- Update the manager behind an open editor, without taking focus or opening
-- a list that the user already closed. Replace items in the same quickfix ID.
---@param id string
+2 -1
View File
@@ -45,8 +45,9 @@ function M.list(views, orphans)
end
vim.fn.setqflist({}, " ", { title = "Comments", items = M.items(views, orphans) })
local id = vim.fn.getqflist({ id = 0 }).id
vim.cmd.copen()
return vim.fn.getqflist({ id = 0 }).id
return id
end
return M
+46
View File
@@ -240,5 +240,51 @@ describe(":CommentClear", function()
local namespace = vim.api.nvim_get_namespaces().scratch_comments
expect.equality(#store.all(), 0)
expect.equality(#vim.api.nvim_buf_get_extmarks(source, namespace, 0, -1, {}), 0)
expect.equality(vim.fn.getqflist(), {})
end)
it("does not clear a list installed by a quickfix window hook", function()
local qf_buf = vim.api.nvim_get_current_buf()
vim.cmd.cclose()
vim.api.nvim_buf_delete(qf_buf, { force = true })
local comment_list_id
local hook = vim.api.nvim_create_autocmd("FileType", {
pattern = "qf",
once = true,
callback = function()
comment_list_id = vim.fn.getqflist({ id = 0 }).id
vim.fn.setqflist({}, " ", { items = { { text = "keep this" } } })
end,
})
vim.cmd.CommentList()
pcall(vim.api.nvim_del_autocmd, hook)
assert(comment_list_id, "expected the quickfix FileType hook to run")
vim.cmd.CommentClear()
expect.equality(vim.fn.getqflist()[1].text, "keep this")
expect.equality(vim.fn.getqflist({ id = comment_list_id, items = 1 }).items, {})
end)
it("empties the comment list in history without changing the current list", function()
local comment_list_id = vim.fn.getqflist({ id = 0 }).id
vim.fn.setqflist({}, " ", {
title = "Other diagnostics",
items = {
{ filename = "other.lua", lnum = 2, text = "first" },
{ filename = "other.lua", lnum = 3, text = "second" },
},
})
local current_list = vim.fn.getqflist({ id = 0, items = 1, title = 1 })
local qf_win = vim.api.nvim_get_current_win()
vim.api.nvim_win_set_cursor(qf_win, { 2, 0 })
vim.cmd.CommentClear()
expect.equality(vim.fn.getqflist({ id = comment_list_id, items = 1 }), {
id = comment_list_id,
items = {},
})
expect.equality(vim.fn.getqflist({ id = 0, items = 1, title = 1 }), current_list)
expect.equality(vim.api.nvim_get_current_win(), qf_win)
expect.equality(vim.api.nvim_win_get_cursor(qf_win), { 2, 0 })
end)
end)