refactor(#2826): add lifecycle logging to all Explorer members

This commit is contained in:
Alexander Courtis 2025-06-16 13:55:35 +10:00
parent fc81249d4f
commit 54439447f1
9 changed files with 63 additions and 20 deletions

View File

@ -649,6 +649,7 @@ Following is the default configuration. See |nvim-tree-opts| for details. >lua
dev = false, dev = false,
diagnostics = false, diagnostics = false,
git = false, git = false,
lifecycle = true,
profile = false, profile = false,
watcher = false, watcher = false,
}, },

View File

@ -31,7 +31,7 @@ local Clipboard = Class:extend()
---@protected ---@protected
---@param args ClipboardArgs ---@param args ClipboardArgs
function Clipboard:new(args) function Clipboard:new(args)
args.explorer:log_lifecycle("Clipboard:new") args.explorer:log_new("Clipboard")
self.explorer = args.explorer self.explorer = args.explorer
@ -44,6 +44,10 @@ function Clipboard:new(args)
self.reg = self.explorer.opts.actions.use_system_clipboard and "+" or "1" self.reg = self.explorer.opts.actions.use_system_clipboard and "+" or "1"
end end
function Clipboard:destroy()
self.explorer:log_destroy("Clipboard")
end
---@param source string ---@param source string
---@param destination string ---@param destination string
---@return boolean ---@return boolean

View File

@ -23,7 +23,7 @@ local Filters = Class:extend()
---@protected ---@protected
---@param args FiltersArgs ---@param args FiltersArgs
function Filters:new(args) function Filters:new(args)
args.explorer:log_lifecycle("Filters:new") args.explorer:log_new("Filters")
self.explorer = args.explorer self.explorer = args.explorer
self.ignore_list = {} self.ignore_list = {}
@ -52,6 +52,10 @@ function Filters:new(args)
end end
end end
function Filters:destroy()
self.explorer:log_destroy("Filters")
end
---@private ---@private
---@param path string ---@param path string
---@return boolean ---@return boolean

View File

@ -56,18 +56,18 @@ function Explorer:new(args)
self.uid_explorer = vim.loop.hrtime() self.uid_explorer = vim.loop.hrtime()
self.augroup_id = vim.api.nvim_create_augroup("NvimTree_Explorer_" .. self.uid_explorer, {}) 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.open = true
self.opts = config self.opts = config
self.sorters = Sorter({ explorer = self }) self.clipboard = Clipboard({ explorer = self })
self.renderer = Renderer({ explorer = self }) self.filters = Filters({ explorer = self })
self.filters = Filters({ explorer = self }) self.live_filter = LiveFilter({ explorer = self })
self.live_filter = LiveFilter({ explorer = self }) self.marks = Marks({ explorer = self })
self.marks = Marks({ explorer = self }) self.renderer = Renderer({ explorer = self })
self.clipboard = Clipboard({ explorer = self }) self.sorters = Sorter({ explorer = self })
self.window = Window({ explorer = self }) self.window = Window({ explorer = self })
self:create_autocmds() self:create_autocmds()
@ -75,7 +75,15 @@ function Explorer:new(args)
end end
function Explorer:destroy() 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) 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 ---Log a lifecycle message with uid_explorer and absolute_path
---@param msg string? ---@param msg string?
function Explorer:log_lifecycle(msg) function Explorer:log_new(msg)
log.line("lifecycle", "%-15s %d %s", msg, self.uid_explorer, self.absolute_path) 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 end
function Explorer:setup(opts) function Explorer:setup(opts)

View File

@ -20,7 +20,7 @@ local LiveFilter = Class:extend()
---@protected ---@protected
---@param args LiveFilterArgs ---@param args LiveFilterArgs
function LiveFilter:new(args) function LiveFilter:new(args)
args.explorer:log_lifecycle("LiveFilter:new") args.explorer:log_new("LiveFilter")
self.explorer = args.explorer self.explorer = args.explorer
self.prefix = self.explorer.opts.live_filter.prefix self.prefix = self.explorer.opts.live_filter.prefix
@ -28,6 +28,10 @@ function LiveFilter:new(args)
self.filter = nil self.filter = nil
end end
function LiveFilter:destroy()
self.explorer:log_destroy("LiveFilter")
end
---@param node_ Node? ---@param node_ Node?
local function reset_filter(self, node_) local function reset_filter(self, node_)
node_ = node_ or self.explorer node_ = node_ or self.explorer

View File

@ -19,11 +19,15 @@ local Sorter = Class:extend()
---@protected ---@protected
---@param args SorterArgs ---@param args SorterArgs
function Sorter:new(args) function Sorter:new(args)
args.explorer:log_lifecycle("Sorter:new") args.explorer:log_new("Sorter")
self.explorer = args.explorer self.explorer = args.explorer
end end
function Sorter:destroy()
self.explorer:log_destroy("Sorter")
end
---Create a shallow copy of a portion of a list. ---Create a shallow copy of a portion of a list.
---@param t table ---@param t table
---@param first integer First index, inclusive ---@param first integer First index, inclusive

View File

@ -50,7 +50,7 @@ local Window = Class:extend()
---@protected ---@protected
---@param args WindowArgs ---@param args WindowArgs
function Window:new(args) function Window:new(args)
args.explorer:log_lifecycle("Window:new") args.explorer:log_new("Window")
self.explorer = args.explorer self.explorer = args.explorer
self.adaptive_size = false self.adaptive_size = false
@ -86,6 +86,10 @@ function Window:new(args)
self.initial_width = self:get_width() self.initial_width = self:get_width()
end end
function Window:destroy()
self.explorer:log_destroy("Window")
end
-- The initial state of a tab -- The initial state of a tab
local tabinitial = { local tabinitial = {
-- The position of the cursor { line, column } -- The position of the cursor { line, column }

View File

@ -25,13 +25,17 @@ local Marks = Class:extend()
---@protected ---@protected
---@param args MarksArgs ---@param args MarksArgs
function Marks:new(args) function Marks:new(args)
args.explorer:log_lifecycle("Marks:new") args.explorer:log_new("Marks")
self.explorer = args.explorer self.explorer = args.explorer
self.marks = {} self.marks = {}
end end
function Marks:destroy()
self.explorer:log_destroy("Marks")
end
---Clear all marks and reload if watchers disabled ---Clear all marks and reload if watchers disabled
---@private ---@private
function Marks:clear_reload() function Marks:clear_reload()

View File

@ -25,11 +25,15 @@ local Renderer = Class:extend()
---@protected ---@protected
---@param args RendererArgs ---@param args RendererArgs
function Renderer:new(args) function Renderer:new(args)
args.explorer:log_lifecycle("Renderer:new") args.explorer:log_new("Renderer")
self.explorer = args.explorer self.explorer = args.explorer
end end
function Renderer:destroy()
self.explorer:log_destroy("Renderer")
end
---@private ---@private
---@param bufnr number ---@param bufnr number
---@param lines string[] ---@param lines string[]