performance improvements (#116)

closes #111
This commit is contained in:
Barrett Ruth 2026-02-12 16:59:13 -05:00 committed by GitHub
parent 330e2bc9b8
commit 9a0b812f69
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 590 additions and 104 deletions

View file

@ -1,10 +1,17 @@
local M = {}
local enabled = false
local log_file = nil
---@param val boolean
---@param val boolean|string
function M.set_enabled(val)
enabled = val
if type(val) == 'string' then
enabled = true
log_file = val
else
enabled = val
log_file = nil
end
end
---@param msg string
@ -13,7 +20,16 @@ function M.dbg(msg, ...)
if not enabled then
return
end
vim.notify('[diffs.nvim]: ' .. string.format(msg, ...), vim.log.levels.DEBUG)
local formatted = '[diffs.nvim]: ' .. string.format(msg, ...)
if log_file then
local f = io.open(log_file, 'a')
if f then
f:write(string.format('%.6fs', vim.uv.hrtime() / 1e9) .. ' ' .. formatted .. '\n')
f:close()
end
else
vim.notify(formatted, vim.log.levels.DEBUG)
end
end
return M