mirror of
https://github.com/kristoferssolo/telescope-frecency.nvim.git
synced 2025-10-21 20:10:38 +00:00
feat: pretty print timer (#251)
* feat: store times for duplicated keys * feat: add func for pretty print timer
This commit is contained in:
parent
db32047232
commit
a75b403ea0
@ -17,8 +17,40 @@ function M.track(event)
|
||||
end
|
||||
end
|
||||
if M.has_lazy then
|
||||
require("lazy.stats").track("[telescope-frecency] " .. event)
|
||||
local stats = require "lazy.stats"
|
||||
---@param n integer
|
||||
---@return string
|
||||
local function make_key(n)
|
||||
return ("[telescope-frecency] %s: %d"):format(event, n)
|
||||
end
|
||||
local key
|
||||
local num = 0
|
||||
while true do
|
||||
key = make_key(num)
|
||||
if not stats._stats.times[key] then
|
||||
break
|
||||
end
|
||||
num = num + 1
|
||||
end
|
||||
stats.track(key)
|
||||
end
|
||||
end
|
||||
|
||||
---@return string
|
||||
function M.pp()
|
||||
local times = require("lazy.stats")._stats.times
|
||||
local result = vim.tbl_map(function(k)
|
||||
return { event = k, t = times[k] }
|
||||
end, vim.tbl_keys(times))
|
||||
table.sort(result, function(a, b)
|
||||
return a.t < b.t
|
||||
end)
|
||||
return table.concat(
|
||||
vim.tbl_map(function(r)
|
||||
return ("%8.3f : %s"):format(r.t, r.event)
|
||||
end, result),
|
||||
"\n"
|
||||
)
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Loading…
Reference in New Issue
Block a user