Revert "refactor(#2871, #2886): multi instance: node classes created (#2916)"

This reverts commit 38aac09151.
This commit is contained in:
Alexander Courtis
2024-10-08 18:07:47 +11:00
parent 010ae0365a
commit 50e919426a
43 changed files with 742 additions and 835 deletions

View File

@@ -4,22 +4,20 @@ local ICON_PLACEMENT = require("nvim-tree.enum").ICON_PLACEMENT
local Decorator = require("nvim-tree.renderer.decorator")
---@class (exact) DecoratorBookmarks: Decorator
---@field icon HighlightedString?
---@field icon HighlightedString
local DecoratorBookmarks = Decorator:new()
---Static factory method
---@param opts table
---@param explorer Explorer
---@return DecoratorBookmarks
function DecoratorBookmarks:create(opts, explorer)
---@type DecoratorBookmarks
local o = {
function DecoratorBookmarks:new(opts, explorer)
local o = Decorator.new(self, {
explorer = explorer,
enabled = true,
hl_pos = HL_POSITION[opts.renderer.highlight_bookmarks] or HL_POSITION.none,
icon_placement = ICON_PLACEMENT[opts.renderer.icons.bookmarks_placement] or ICON_PLACEMENT.none,
}
o = self:new(o) --[[@as DecoratorBookmarks]]
})
---@cast o DecoratorBookmarks
if opts.renderer.icons.show.bookmarks then
o.icon = {

View File

@@ -4,22 +4,21 @@ local ICON_PLACEMENT = require("nvim-tree.enum").ICON_PLACEMENT
local Decorator = require("nvim-tree.renderer.decorator")
---@class (exact) DecoratorCopied: Decorator
---@field icon HighlightedString?
---@field enabled boolean
---@field icon HighlightedString|nil
local DecoratorCopied = Decorator:new()
---Static factory method
---@param opts table
---@param explorer Explorer
---@return DecoratorCopied
function DecoratorCopied:create(opts, explorer)
---@type DecoratorCopied
local o = {
function DecoratorCopied:new(opts, explorer)
local o = Decorator.new(self, {
explorer = explorer,
enabled = true,
hl_pos = HL_POSITION[opts.renderer.highlight_clipboard] or HL_POSITION.none,
icon_placement = ICON_PLACEMENT.none,
}
o = self:new(o) --[[@as DecoratorCopied]]
})
---@cast o DecoratorCopied
return o
end

View File

@@ -4,21 +4,21 @@ local ICON_PLACEMENT = require("nvim-tree.enum").ICON_PLACEMENT
local Decorator = require("nvim-tree.renderer.decorator")
---@class (exact) DecoratorCut: Decorator
---@field enabled boolean
---@field icon HighlightedString|nil
local DecoratorCut = Decorator:new()
---Static factory method
---@param opts table
---@param explorer Explorer
---@return DecoratorCut
function DecoratorCut:create(opts, explorer)
---@type DecoratorCut
local o = {
function DecoratorCut:new(opts, explorer)
local o = Decorator.new(self, {
explorer = explorer,
enabled = true,
hl_pos = HL_POSITION[opts.renderer.highlight_clipboard] or HL_POSITION.none,
icon_placement = ICON_PLACEMENT.none,
}
o = self:new(o) --[[@as DecoratorCut]]
})
---@cast o DecoratorCut
return o
end

View File

@@ -33,22 +33,20 @@ local ICON_KEYS = {
}
---@class (exact) DecoratorDiagnostics: Decorator
---@field icons HighlightedString[]?
---@field icons HighlightedString[]
local DecoratorDiagnostics = Decorator:new()
---Static factory method
---@param opts table
---@param explorer Explorer
---@return DecoratorDiagnostics
function DecoratorDiagnostics:create(opts, explorer)
---@type DecoratorDiagnostics
local o = {
function DecoratorDiagnostics:new(opts, explorer)
local o = Decorator.new(self, {
explorer = explorer,
enabled = opts.diagnostics.enable,
hl_pos = HL_POSITION[opts.renderer.highlight_diagnostics] or HL_POSITION.none,
icon_placement = ICON_PLACEMENT[opts.renderer.icons.diagnostics_placement] or ICON_PLACEMENT.none,
}
o = self:new(o) --[[@as DecoratorDiagnostics]]
})
---@cast o DecoratorDiagnostics
if not o.enabled then
return o

View File

@@ -1,4 +1,5 @@
local notify = require("nvim-tree.notify")
local explorer_node = require("nvim-tree.explorer.node")
local HL_POSITION = require("nvim-tree.enum").HL_POSITION
local ICON_PLACEMENT = require("nvim-tree.enum").ICON_PLACEMENT
@@ -9,25 +10,23 @@ local Decorator = require("nvim-tree.renderer.decorator")
---@field ord number decreasing priority
---@class (exact) DecoratorGit: Decorator
---@field file_hl table<string, string>? by porcelain status e.g. "AM"
---@field folder_hl table<string, string>? by porcelain status
---@field icons_by_status HighlightedStringGit[]? by human status
---@field icons_by_xy table<string, HighlightedStringGit[]>? by porcelain status
---@field file_hl table<string, string> by porcelain status e.g. "AM"
---@field folder_hl table<string, string> by porcelain status
---@field icons_by_status HighlightedStringGit[] by human status
---@field icons_by_xy table<string, HighlightedStringGit[]> by porcelain status
local DecoratorGit = Decorator:new()
---Static factory method
---@param opts table
---@param explorer Explorer
---@return DecoratorGit
function DecoratorGit:create(opts, explorer)
---@type DecoratorGit
local o = {
function DecoratorGit:new(opts, explorer)
local o = Decorator.new(self, {
explorer = explorer,
enabled = opts.git.enable,
hl_pos = HL_POSITION[opts.renderer.highlight_git] or HL_POSITION.none,
icon_placement = ICON_PLACEMENT[opts.renderer.icons.git_placement] or ICON_PLACEMENT.none,
}
o = self:new(o) --[[@as DecoratorGit]]
})
---@cast o DecoratorGit
if not o.enabled then
return o
@@ -148,7 +147,7 @@ function DecoratorGit:calculate_icons(node)
return nil
end
local git_status = node:get_git_status()
local git_status = explorer_node.get_git_status(node)
if git_status == nil then
return nil
end
@@ -209,7 +208,7 @@ function DecoratorGit:calculate_highlight(node)
return nil
end
local git_status = node:get_git_status()
local git_status = explorer_node.get_git_status(node)
if not git_status then
return nil
end

View File

@@ -1,24 +1,23 @@
local HL_POSITION = require("nvim-tree.enum").HL_POSITION
local ICON_PLACEMENT = require("nvim-tree.enum").ICON_PLACEMENT
local explorer_node = require("nvim-tree.explorer.node")
local Decorator = require("nvim-tree.renderer.decorator")
---@class (exact) DecoratorHidden: Decorator
---@field icon HighlightedString?
---@field icon HighlightedString|nil
local DecoratorHidden = Decorator:new()
---Static factory method
---@param opts table
---@param explorer Explorer
---@return DecoratorHidden
function DecoratorHidden:create(opts, explorer)
---@type DecoratorHidden
local o = {
function DecoratorHidden:new(opts, explorer)
local o = Decorator.new(self, {
explorer = explorer,
enabled = true,
hl_pos = HL_POSITION[opts.renderer.highlight_hidden] or HL_POSITION.none,
icon_placement = ICON_PLACEMENT[opts.renderer.icons.hidden_placement] or ICON_PLACEMENT.none,
}
o = self:new(o) --[[@as DecoratorHidden]]
})
---@cast o DecoratorHidden
if opts.renderer.icons.show.hidden then
o.icon = {
@@ -35,7 +34,7 @@ end
---@param node Node
---@return HighlightedString[]|nil icons
function DecoratorHidden:calculate_icons(node)
if self.enabled and node:is_dotfile() then
if self.enabled and explorer_node.is_dotfile(node) then
return { self.icon }
end
end
@@ -44,7 +43,7 @@ end
---@param node Node
---@return string|nil group
function DecoratorHidden:calculate_highlight(node)
if not self.enabled or self.hl_pos == HL_POSITION.none or not node:is_dotfile() then
if not self.enabled or self.hl_pos == HL_POSITION.none or (not explorer_node.is_dotfile(node)) then
return nil
end

View File

@@ -1,8 +1,6 @@
local HL_POSITION = require("nvim-tree.enum").HL_POSITION
local ICON_PLACEMENT = require("nvim-tree.enum").ICON_PLACEMENT
---Abstract Decorator
---Uses the factory pattern to instantiate child instances.
---@class (exact) Decorator
---@field private __index? table
---@field protected explorer Explorer

View File

@@ -9,19 +9,17 @@ local Decorator = require("nvim-tree.renderer.decorator")
---@field icon HighlightedString|nil
local DecoratorModified = Decorator:new()
---Static factory method
---@param opts table
---@param explorer Explorer
---@return DecoratorModified
function DecoratorModified:create(opts, explorer)
---@type DecoratorModified
local o = {
function DecoratorModified:new(opts, explorer)
local o = Decorator.new(self, {
explorer = explorer,
enabled = opts.modified.enable,
hl_pos = HL_POSITION[opts.renderer.highlight_modified] or HL_POSITION.none,
icon_placement = ICON_PLACEMENT[opts.renderer.icons.modified_placement] or ICON_PLACEMENT.none,
}
o = self:new(o) --[[@as DecoratorModified]]
})
---@cast o DecoratorModified
if not o.enabled then
return o

View File

@@ -6,22 +6,21 @@ local ICON_PLACEMENT = require("nvim-tree.enum").ICON_PLACEMENT
local Decorator = require("nvim-tree.renderer.decorator")
---@class (exact) DecoratorOpened: Decorator
---@field enabled boolean
---@field icon HighlightedString|nil
local DecoratorOpened = Decorator:new()
---Static factory method
---@param opts table
---@param explorer Explorer
---@return DecoratorOpened
function DecoratorOpened:create(opts, explorer)
---@type DecoratorOpened
local o = {
function DecoratorOpened:new(opts, explorer)
local o = Decorator.new(self, {
explorer = explorer,
enabled = true,
hl_pos = HL_POSITION[opts.renderer.highlight_opened_files] or HL_POSITION.none,
icon_placement = ICON_PLACEMENT.none,
}
o = self:new(o) --[[@as DecoratorOpened]]
})
---@cast o DecoratorOpened
return o
end