feat(picker.debug): debug option to detect garbage collection leaks

This commit is contained in:
Folke Lemaitre 2025-01-20 10:29:55 +01:00
parent 52c5ba857c
commit b59f4ff477
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
2 changed files with 10 additions and 0 deletions

View file

@ -322,6 +322,7 @@ local defaults = {
---@class snacks.picker.debug
debug = {
scores = false, -- show scores in the list
leaks = false, -- show when pickers don't get garbage collected
},
}

View file

@ -55,6 +55,15 @@ function M.new(opts)
if self.opts.source == "resume" then
return M.resume()
end
if self.opts.debug.leaks then
collectgarbage("collect")
local picker_count = vim.tbl_count(M._pickers)
if picker_count > 0 then
Snacks.notify.error("` " .. picker_count .. " ` active pickers.", { title = "Snacks Picker" })
end
end
self.visual = Snacks.picker.util.visual()
self.start_time = uv.hrtime()
Snacks.picker.current = self