Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(commands): NvimTreeOpenLog to open log file #2560

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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*
hinell marked this conversation as resolved.
Show resolved Hide resolved

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 @@ -2019,7 +2028,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 @@ -2030,6 +2039,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