From 5231562cafd7044c827c8b5cfd7b1391894761cc Mon Sep 17 00:00:00 2001 From: Azad <49314270+Akmadan23@users.noreply.github.com> Date: Sat, 25 Nov 2023 21:45:59 +0100 Subject: [PATCH] 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 784ee91cc6178692a28d0907880560870020522b. * Revert "Add documentation" This reverts commit 6dc396d0a5edcdeb4b50bbfb6966708befe5b497. * feat(log): add node inspection function --------- Co-authored-by: Alexander Courtis --- lua/nvim-tree/log.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lua/nvim-tree/log.lua b/lua/nvim-tree/log.lua index 10d5c4dc..72dce2e9 100644 --- a/lua/nvim-tree/log.lua +++ b/lua/nvim-tree/log.lua @@ -61,6 +61,26 @@ function M.line(typ, fmt, ...) end end +local inspect_opts = {} + +--- @param opts table +function M.set_inspect_opts(opts) + inspect_opts = opts +end + +--- Write to log file the inspection of a node +--- defaults to the node under cursor if none is provided +--- @param typ string as per log.types config +--- @param node table|nil node to be inspected +--- @param fmt string for string.format +--- @vararg any arguments for string.format +function M.node(typ, node, fmt, ...) + if M.enabled(typ) then + node = node or require("nvim-tree.lib").get_node_at_cursor() + 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)), ...) + end +end + --- Logging is enabled for typ or all --- @param typ string as per log.types config --- @return boolean