Skip to content

Commit

Permalink
feat(log): add command & public api
Browse files Browse the repository at this point in the history
New api.log for log utils
New command: NvimTreeOpenLog to open log file
  • Loading branch information
hinell committed Nov 27, 2023
1 parent 5e4475d commit e6a1555
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
22 changes: 21 additions & 1 deletion doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ CONTENTS *nvim-tree*
6.7 API Marks |nvim-tree-api.marks|
6.8 API Config |nvim-tree-api.config|
6.9 API Commands |nvim-tree-api.commands|
6.10 API Log |nvim-tree-api.log|
7. Mappings |nvim-tree-mappings|
7.1 Mappings: Default |nvim-tree-mappings-default|
8. Highlight |nvim-tree-highlight|
Expand Down Expand Up @@ -319,6 +320,14 @@ via |nvim-tree.on_attach| e.g. >

Calls: `api.tree.collapse_all(true)`

*:NvimTreeOpenLog*

Opens the nvim-tree log file in a new window.

See |nvim-tree-opts-log|

Calls: `api.log.open()`

==============================================================================
4. SETUP *nvim-tree-setup*

Expand Down Expand Up @@ -2018,7 +2027,7 @@ config.mappings.get_keymap_default()
(table) as per |nvim_buf_get_keymap()|

==============================================================================
6.8 API COMMANDS *nvim-tree-api.commands*
6.9 API COMMANDS *nvim-tree-api.commands*

commands.get() *nvim-tree-api.commands.get()*
Retrieve all commands, see |nvim-tree-commands|
Expand All @@ -2029,6 +2038,17 @@ commands.get() *nvim-tree-api.commands.get()*
{command} (function)
{opts} (table)

==============================================================================
6.10 API LOG *nvim-tree-api.log*

log.get_path() *nvim-tree-api.log.get()*
Get path to an nvim-tree log file.

Return: ~
{path} (string)
log.open() *nvim-tree-api.log.open()*
Open log file in new window.

==============================================================================
7. MAPPINGS *nvim-tree-mappings*

Expand Down
4 changes: 4 additions & 0 deletions lua/nvim-tree/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,8 @@ Api.commands.get = wrap(function()
return require("nvim-tree.commands").get()
end)

Api.log = {}
Api.log.open = wrap(require("nvim-tree.log").open)
Api.log.get_path = wrap(require("nvim-tree.log").get_path)

return Api
10 changes: 10 additions & 0 deletions lua/nvim-tree/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ local CMDS = {
api.tree.collapse_all(true)
end,
},
{
name = "NvimTreeOpenLog",
opts = {
desc = "nvim-tree: open log file",
bar = true,
},
command = function()
api.log.open()
end,
},
}

function M.get()
Expand Down
21 changes: 20 additions & 1 deletion lua/nvim-tree/log.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local notify = require "nvim-tree.notify"

local M = {
config = nil,
path = nil,
Expand Down Expand Up @@ -95,7 +97,24 @@ function M.setup(opts)
if M.config.truncate then
os.remove(M.path)
end
require("nvim-tree.notify").debug("nvim-tree.lua logging to " .. M.path)
notify.debug("nvim-tree.lua logging to " .. M.path)
end
end

--- Returns path to the log file
--- @return string|nil
function M.get_path()
if M.path ~= nil then
return M.path
end
end

--- Opens ua the log file
function M.open()
if M.path ~= nil then
vim.cmd("tab :drop" .. M.path)
else
notify.warn("nvim-tree: logging is not enabled. See `h nvim-tree-opts-log`")
end
end

Expand Down

0 comments on commit e6a1555

Please sign in to comment.