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,
diagnostics = false,
git = false,
lifecycle = true,
profile = false,
watcher = false,
},

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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 }

View File

@ -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()

View File

@ -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[]