From 2882d32cd5cf2b43232ffb516fc2a5ae1f363c76 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 12 Apr 2021 11:16:18 +0000 Subject: [PATCH] Format how cache is dumped --- lua/gitsigns.lua | 31 ++++++++++++++++++++++++++++++- teal/gitsigns.tl | 31 ++++++++++++++++++++++++++++++- types/types.d.tl | 8 ++++++-- 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/lua/gitsigns.lua b/lua/gitsigns.lua index 35ae559..e72a26d 100644 --- a/lua/gitsigns.lua +++ b/lua/gitsigns.lua @@ -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) diff --git a/teal/gitsigns.tl b/teal/gitsigns.tl index d4218c7..54c6933 100644 --- a/teal/gitsigns.tl +++ b/teal/gitsigns.tl @@ -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 = path[#path] + if key == 'staged_text' then + local item = 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 = 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} diff --git a/types/types.d.tl b/types/types.d.tl index 92f087e..2e0f4f5 100644 --- a/types/types.d.tl +++ b/types/types.d.tl @@ -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)