Format how cache is dumped

This commit is contained in:
Lewis Russell 2021-04-12 11:16:18 +00:00
parent 126decc4ea
commit 2882d32cd5
3 changed files with 66 additions and 4 deletions

View File

@ -571,7 +571,36 @@ end
local function add_debug_functions()
M.dump_cache = function()
api.nvim_echo({ { vim.inspect(cache) } }, false, {})
api.nvim_echo({ { vim.inspect(cache, {
process = function(raw_item, path)
if path[#path] == vim.inspect.METATABLE then
return nil
elseif type(raw_item) == "function" then
return nil
elseif type(raw_item) == "table" then
local key = path[#path]
if key == 'staged_text' then
local item = raw_item
return { '...', length = #item, head = item[1] }
elseif not vim.tbl_isempty(raw_item) and vim.tbl_contains({
'hunks', 'staged_diffs', }, key) then
return { '...', length = #vim.tbl_keys(raw_item) }
elseif key == 'pending_signs' then
local keys = vim.tbl_keys(raw_item)
local max = 100
if #keys > max then
keys.length = #keys
for i = max, #keys do
keys[i] = nil
end
keys[max] = '...'
end
return keys
end
end
return raw_item
end,
}), }, }, false, {})
end
M.debug_messages = function(noecho)

View File

@ -571,7 +571,36 @@ end
local function add_debug_functions()
M.dump_cache = function()
api.nvim_echo({{vim.inspect(cache)}}, false, {})
api.nvim_echo({{vim.inspect(cache, {
process = function(raw_item: any, path: {string}): any
if path[#path] == vim.inspect.METATABLE then
return nil
elseif raw_item is function then
return nil
elseif raw_item is table then
local key <const> = path[#path]
if key == 'staged_text' then
local item <const> = raw_item as {string}
return { '...', length=#item, head=item[1] }
elseif not vim.tbl_isempty(raw_item) and vim.tbl_contains({
'hunks', 'staged_diffs' }, key) then
return { '...', length=#vim.tbl_keys(raw_item) }
elseif key == 'pending_signs' then
local keys = vim.tbl_keys(raw_item)
local max <const> = 100
if #keys > max then
keys.length = #keys
for i = max, #keys do
keys[i] = nil
end
keys[max] = '...'
end
return keys
end
end
return raw_item
end
})}}, false, {})
end
M.debug_messages = function(noecho: boolean): {string}

View File

@ -275,8 +275,12 @@ global record vim
indent: string
process: function
end
inspect: function(any): string
inspect: function(any, InspectOptions): string
record inspect
METATABLE: any
KEY: any
metamethod __call: function(inspect, any, InspectOptions): string
metamethod __call: function(inspect, any): string
end
wait: function(number, function, number, boolean)