From e6a15554844ae4c4d66681a1a797c0867f6fa75b Mon Sep 17 00:00:00 2001 From: hinell Date: Mon, 27 Nov 2023 00:36:59 +0300 Subject: [PATCH] feat(log): add command & public api New api.log for log utils New command: NvimTreeOpenLog to open log file --- doc/nvim-tree-lua.txt | 22 +++++++++++++++++++++- lua/nvim-tree/api.lua | 4 ++++ lua/nvim-tree/commands.lua | 10 ++++++++++ lua/nvim-tree/log.lua | 21 ++++++++++++++++++++- 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index ed455769a74..17248758b1e 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -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| @@ -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* @@ -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| @@ -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* diff --git a/lua/nvim-tree/api.lua b/lua/nvim-tree/api.lua index 886ff345f63..dbc1f884db7 100644 --- a/lua/nvim-tree/api.lua +++ b/lua/nvim-tree/api.lua @@ -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 diff --git a/lua/nvim-tree/commands.lua b/lua/nvim-tree/commands.lua index e5013f5753e..961ed690917 100644 --- a/lua/nvim-tree/commands.lua +++ b/lua/nvim-tree/commands.lua @@ -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() diff --git a/lua/nvim-tree/log.lua b/lua/nvim-tree/log.lua index 72dce2e9f0e..31b49c3b768 100644 --- a/lua/nvim-tree/log.lua +++ b/lua/nvim-tree/log.lua @@ -1,3 +1,5 @@ +local notify = require "nvim-tree.notify" + local M = { config = nil, path = nil, @@ -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