Skip to content

Commit 5231562

Browse files
feat(log): add node inspection function (#2541)
* feat: add `api.tree.inspect_node_under_cursor` * Add documentation * Revert "feat: add `api.tree.inspect_node_under_cursor`" This reverts commit 784ee91. * Revert "Add documentation" This reverts commit 6dc396d. * feat(log): add node inspection function --------- Co-authored-by: Alexander Courtis <alex@courtis.org>
1 parent db796fc commit 5231562

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lua/nvim-tree/log.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,26 @@ function M.line(typ, fmt, ...)
6161
end
6262
end
6363

64+
local inspect_opts = {}
65+
66+
--- @param opts table
67+
function M.set_inspect_opts(opts)
68+
inspect_opts = opts
69+
end
70+
71+
--- Write to log file the inspection of a node
72+
--- defaults to the node under cursor if none is provided
73+
--- @param typ string as per log.types config
74+
--- @param node table|nil node to be inspected
75+
--- @param fmt string for string.format
76+
--- @vararg any arguments for string.format
77+
function M.node(typ, node, fmt, ...)
78+
if M.enabled(typ) then
79+
node = node or require("nvim-tree.lib").get_node_at_cursor()
80+
M.raw(typ, string.format("[%s] [%s] %s\n%s\n", os.date "%Y-%m-%d %H:%M:%S", typ, (fmt or "???"), vim.inspect(node, inspect_opts)), ...)
81+
end
82+
end
83+
6484
--- Logging is enabled for typ or all
6585
--- @param typ string as per log.types config
6686
--- @return boolean

0 commit comments

Comments
 (0)