diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index df57ca03..a98fe31e 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -649,6 +649,7 @@ Following is the default configuration. See |nvim-tree-opts| for details. >lua dev = false, diagnostics = false, git = false, + lifecycle = true, profile = false, watcher = false, }, diff --git a/lua/nvim-tree/actions/fs/clipboard.lua b/lua/nvim-tree/actions/fs/clipboard.lua index a8c6e15e..aa9ae2c8 100644 --- a/lua/nvim-tree/actions/fs/clipboard.lua +++ b/lua/nvim-tree/actions/fs/clipboard.lua @@ -31,7 +31,7 @@ local Clipboard = Class:extend() ---@protected ---@param args ClipboardArgs function Clipboard:new(args) - args.explorer:log_lifecycle("Clipboard:new") + args.explorer:log_new("Clipboard") self.explorer = args.explorer @@ -44,6 +44,10 @@ function Clipboard:new(args) self.reg = self.explorer.opts.actions.use_system_clipboard and "+" or "1" end +function Clipboard:destroy() + self.explorer:log_destroy("Clipboard") +end + ---@param source string ---@param destination string ---@return boolean diff --git a/lua/nvim-tree/explorer/filters.lua b/lua/nvim-tree/explorer/filters.lua index c6640fb4..6066e8a3 100644 --- a/lua/nvim-tree/explorer/filters.lua +++ b/lua/nvim-tree/explorer/filters.lua @@ -23,7 +23,7 @@ local Filters = Class:extend() ---@protected ---@param args FiltersArgs function Filters:new(args) - args.explorer:log_lifecycle("Filters:new") + args.explorer:log_new("Filters") self.explorer = args.explorer self.ignore_list = {} @@ -52,6 +52,10 @@ function Filters:new(args) end end +function Filters:destroy() + self.explorer:log_destroy("Filters") +end + ---@private ---@param path string ---@return boolean diff --git a/lua/nvim-tree/explorer/init.lua b/lua/nvim-tree/explorer/init.lua index 4c12ff2f..6c1457fa 100644 --- a/lua/nvim-tree/explorer/init.lua +++ b/lua/nvim-tree/explorer/init.lua @@ -56,18 +56,18 @@ function Explorer:new(args) self.uid_explorer = vim.loop.hrtime() self.augroup_id = vim.api.nvim_create_augroup("NvimTree_Explorer_" .. self.uid_explorer, {}) - self:log_lifecycle("Explorer:new") + self:log_new("Explorer") - self.open = true - self.opts = config + self.open = true + self.opts = config - self.sorters = Sorter({ explorer = self }) - self.renderer = Renderer({ explorer = self }) - self.filters = Filters({ explorer = self }) - self.live_filter = LiveFilter({ explorer = self }) - self.marks = Marks({ explorer = self }) - self.clipboard = Clipboard({ explorer = self }) - self.window = Window({ explorer = self }) + self.clipboard = Clipboard({ explorer = self }) + self.filters = Filters({ explorer = self }) + self.live_filter = LiveFilter({ explorer = self }) + self.marks = Marks({ explorer = self }) + self.renderer = Renderer({ explorer = self }) + self.sorters = Sorter({ explorer = self }) + self.window = Window({ explorer = self }) self:create_autocmds() @@ -75,7 +75,15 @@ function Explorer:new(args) end function Explorer:destroy() - self:log_lifecycle("Explorer:des") + self.explorer:log_destroy("Explorer") + + self.clipboard:destroy() + self.filters:destroy() + self.live_filter:destroy() + self.marks:destroy() + self.renderer:destroy() + self.sorters:destroy() + self.window:destroy() vim.api.nvim_del_augroup_by_id(self.augroup_id) @@ -591,8 +599,14 @@ end ---Log a lifecycle message with uid_explorer and absolute_path ---@param msg string? -function Explorer:log_lifecycle(msg) - log.line("lifecycle", "%-15s %d %s", msg, self.uid_explorer, self.absolute_path) +function Explorer:log_new(msg) + log.line("lifecycle", "+ %-15s %d %s", msg, self.uid_explorer, self.absolute_path) +end + +---Log a lifecycle message with uid_explorer and absolute_path +---@param msg string? +function Explorer:log_destroy(msg) + log.line("lifecycle", "- %-15s %d %s", msg, self.uid_explorer, self.absolute_path) end function Explorer:setup(opts) diff --git a/lua/nvim-tree/explorer/live-filter.lua b/lua/nvim-tree/explorer/live-filter.lua index c5b5770a..e239471b 100644 --- a/lua/nvim-tree/explorer/live-filter.lua +++ b/lua/nvim-tree/explorer/live-filter.lua @@ -20,7 +20,7 @@ local LiveFilter = Class:extend() ---@protected ---@param args LiveFilterArgs function LiveFilter:new(args) - args.explorer:log_lifecycle("LiveFilter:new") + args.explorer:log_new("LiveFilter") self.explorer = args.explorer self.prefix = self.explorer.opts.live_filter.prefix @@ -28,6 +28,10 @@ function LiveFilter:new(args) self.filter = nil end +function LiveFilter:destroy() + self.explorer:log_destroy("LiveFilter") +end + ---@param node_ Node? local function reset_filter(self, node_) node_ = node_ or self.explorer diff --git a/lua/nvim-tree/explorer/sorter.lua b/lua/nvim-tree/explorer/sorter.lua index 3fd475e3..4e69d36e 100644 --- a/lua/nvim-tree/explorer/sorter.lua +++ b/lua/nvim-tree/explorer/sorter.lua @@ -19,11 +19,15 @@ local Sorter = Class:extend() ---@protected ---@param args SorterArgs function Sorter:new(args) - args.explorer:log_lifecycle("Sorter:new") + args.explorer:log_new("Sorter") self.explorer = args.explorer end +function Sorter:destroy() + self.explorer:log_destroy("Sorter") +end + ---Create a shallow copy of a portion of a list. ---@param t table ---@param first integer First index, inclusive diff --git a/lua/nvim-tree/explorer/window.lua b/lua/nvim-tree/explorer/window.lua index fcf497c7..7633d56c 100644 --- a/lua/nvim-tree/explorer/window.lua +++ b/lua/nvim-tree/explorer/window.lua @@ -50,7 +50,7 @@ local Window = Class:extend() ---@protected ---@param args WindowArgs function Window:new(args) - args.explorer:log_lifecycle("Window:new") + args.explorer:log_new("Window") self.explorer = args.explorer self.adaptive_size = false @@ -86,6 +86,10 @@ function Window:new(args) self.initial_width = self:get_width() end +function Window:destroy() + self.explorer:log_destroy("Window") +end + -- The initial state of a tab local tabinitial = { -- The position of the cursor { line, column } diff --git a/lua/nvim-tree/marks/init.lua b/lua/nvim-tree/marks/init.lua index 3771520c..e0fe9a30 100644 --- a/lua/nvim-tree/marks/init.lua +++ b/lua/nvim-tree/marks/init.lua @@ -25,13 +25,17 @@ local Marks = Class:extend() ---@protected ---@param args MarksArgs function Marks:new(args) - args.explorer:log_lifecycle("Marks:new") + args.explorer:log_new("Marks") self.explorer = args.explorer self.marks = {} end +function Marks:destroy() + self.explorer:log_destroy("Marks") +end + ---Clear all marks and reload if watchers disabled ---@private function Marks:clear_reload() diff --git a/lua/nvim-tree/renderer/init.lua b/lua/nvim-tree/renderer/init.lua index 2e3848a7..e90e2d1a 100644 --- a/lua/nvim-tree/renderer/init.lua +++ b/lua/nvim-tree/renderer/init.lua @@ -25,11 +25,15 @@ local Renderer = Class:extend() ---@protected ---@param args RendererArgs function Renderer:new(args) - args.explorer:log_lifecycle("Renderer:new") + args.explorer:log_new("Renderer") self.explorer = args.explorer end +function Renderer:destroy() + self.explorer:log_destroy("Renderer") +end + ---@private ---@param bufnr number ---@param lines string[]