feat(profiler): on_close can now be a function

This commit is contained in:
Folke Lemaitre 2024-12-07 21:30:18 +01:00
parent 971229e8a9
commit 48a58792a0

View file

@ -144,7 +144,7 @@ local defaults = {
pattern = nil, -- pattern to match for the autocmd
pick = true, -- show a picker after starting the profiler (uses the `startup` preset)
},
---@type table<string, snacks.profiler.Pick|fun():snacks.profiler.Pick>
---@type table<string, snacks.profiler.Pick|fun():snacks.profiler.Pick?>
presets = {
startup = { min_time = 1, sort = false },
on_stop = {},
@ -319,10 +319,19 @@ end
---@param opts? snacks.profiler.Pick.spec
function M.pick(opts)
load()
opts = type(opts) == "function" and opts() or opts or {}
if type(opts) == "function" then
opts = opts()
if not opts then
return
end
end
opts = opts or {}
if opts.preset then
local preset = M.config.presets[opts.preset]
preset = type(preset) == "function" and preset() or preset
preset = type(preset) == "function" and preset()
if not preset then
return
end
opts = vim.tbl_deep_extend("force", {}, preset, opts)
end
---@cast opts snacks.profiler.Pick