feat(util): added trackfn that wraps a function and tracks timings

This commit is contained in:
Folke Lemaitre 2023-01-02 11:26:40 +01:00
parent 2d06faa941
commit 50a456c189
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
1 changed files with 17 additions and 1 deletions

View File

@ -28,6 +28,22 @@ function M.track(data, time)
end
end
---@generic F: fun()
---@param data (string|{[string]:string})?
---@param fn F
---@return F
function M.trackfn(data, fn)
return function(...)
M.track(data)
local ok, ret = pcall(fn, ...)
M.track()
if not ok then
error(ret)
end
return ret
end
end
---@param name string
---@return string
function M.normname(name)
@ -127,7 +143,7 @@ function M.very_lazy()
local function _load()
vim.defer_fn(function()
vim.cmd("do User VeryLazy")
end, 100)
end, 50)
end
vim.api.nvim_create_autocmd("User", {