Skip to content

Commit

Permalink
tooling: add CTDumpNode command
Browse files Browse the repository at this point in the history
similar to CTDumpTree however it dumps the current node at the cursor
for debugging purposes.

Signed-off-by: ldelossa <[email protected]>
  • Loading branch information
ldelossa committed Dec 5, 2021
1 parent ae01f1f commit 6aa9e89
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions lua/calltree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ function M.setup(user_config)
vim.cmd("command! CTDetails lua require('calltree.ui').details()")
vim.cmd("command! CTClearHL lua require('calltree.ui.jumps').set_jump_hl(false)")
vim.cmd("command! CTDumpTree lua require('calltree.ui').dump_tree()")
vim.cmd("command! CTDumpNode lua require('calltree.ui').dump_node()")
end

-- the configured icon set after setup() is ran.
Expand Down
4 changes: 2 additions & 2 deletions lua/calltree/tree/tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@ end
-- buffer for debugging.
--
-- tree : tree_handle - a handle to a valid tree
function M.dump_tree(tree)
function M.dump_tree(node)
local buf = vim.api.nvim_create_buf(true, false)
vim.api.nvim_buf_set_name(buf, "calltree-dump")
vim.cmd("botright split")
local win = vim.api.nvim_get_current_win()
local lines = vim.fn.split(vim.inspect(reg[tree].root), "\n")
local lines = vim.fn.split(vim.inspect(node), "\n")
vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
vim.api.nvim_win_set_buf(win, buf)
vim.api.nvim_set_current_win(win)
Expand Down
7 changes: 6 additions & 1 deletion lua/calltree/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,12 @@ M.dump_tree = function()
if ctx.tree_handle == nil then
return
end
tree.dump_tree(ctx.tree_handle)
tree.dump_tree(tree.get_tree(ctx.tree_handle).root)
end

M.dump_node = function()
local ctx = ui_req_ctx()
tree.dump_tree(ctx.node)
end

return M

0 comments on commit 6aa9e89

Please sign in to comment.