feat(debug): truncate inspect to 2000 lines max

This commit is contained in:
Folke Lemaitre 2025-01-23 10:10:30 +01:00
parent 41ee33725e
commit 570d2191d5
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -12,6 +12,8 @@ M.meta = {
local uv = vim.uv or vim.loop
local MAX_INSPECT_LINES = 2000
vim.schedule(function()
Snacks.util.set_hl({
Indent = "LineNr",
@ -40,7 +42,14 @@ function M.inspect(...)
end
vim.schedule(function()
local title = "Debug: " .. vim.fn.fnamemodify(caller.source:sub(2), ":~:.") .. ":" .. caller.linedefined
Snacks.notify.warn(vim.inspect(len == 1 and obj[1] or len > 0 and obj or nil), { title = title, ft = "lua" })
local lines = vim.split(vim.inspect(len == 1 and obj[1] or len > 0 and obj or nil), "\n")
if #lines > MAX_INSPECT_LINES then
local c = #lines
lines = vim.list_slice(lines, 1, MAX_INSPECT_LINES)
lines[#lines + 1] = ""
lines[#lines + 1] = (c - MAX_INSPECT_LINES) .. " more lines have been truncated …"
end
Snacks.notify.warn(lines, { title = title, ft = "lua" })
end)
end