diff --git a/lua/nvim-tree/log.lua b/lua/nvim-tree/log.lua index 10d5c4dcc18..72dce2e9f0e 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