* refactor(#2875): multi instance renderer * refactor(#2875): multi instance renderer * refactor(#2875): multi instance renderer * refactor(#2875): multi instance renderer * node classes and constructors * node methods * refactor(#2875): multi instance renderer * node classes and constructors * explorer is a directory node * extract methods from explore_node * extract methods from explore_node * extract methods from explore_node * extract methods from lib * use .. name for root node for compatibility * use node.explorer * extract node factory, remove unused code * factories for all nodes, add RootNode * factories for all nodes, add RootNode * use factory pattern for decorators * note regression and commit * fix dir git status regression * destroy nodes, not explorer * add BaseNode:is * revert changes to create-file, handle in #2924 * extract methods from explorer * extract methods from explorer * extract methods from explorer * use Node everywhere in luadoc * extract methods from lib * extract methods from lib * lint * remove unused code * don't call methods on fake root node * get_node_at_cursor returns explorer (root) node instead of { name = '..' } * remove unused inject_node * refactor(#2875): multi instance renderer * refactor(#2875): multi instance renderer * refactor(#2875): multi instance renderer * extract methods from lib * node factory uses stat only * temporary DirectoryNode casting until method extraction into child classes * lua-language-server 3.10.5 -> 3.11.0 * explicitly call Explorer constructor * normalise explorer RootNode new call, tidy annotations
This commit is contained in:
committed by
GitHub
parent
c9104a5d07
commit
38aac09151
@@ -68,14 +68,14 @@ function Builder:new(opts, explorer)
|
||||
virtual_lines = {},
|
||||
decorators = {
|
||||
-- priority order
|
||||
DecoratorCut:new(opts, explorer),
|
||||
DecoratorCopied:new(opts, explorer),
|
||||
DecoratorDiagnostics:new(opts, explorer),
|
||||
DecoratorBookmarks:new(opts, explorer),
|
||||
DecoratorModified:new(opts, explorer),
|
||||
DecoratorHidden:new(opts, explorer),
|
||||
DecoratorOpened:new(opts, explorer),
|
||||
DecoratorGit:new(opts, explorer),
|
||||
DecoratorCut:create(opts, explorer),
|
||||
DecoratorCopied:create(opts, explorer),
|
||||
DecoratorDiagnostics:create(opts, explorer),
|
||||
DecoratorBookmarks:create(opts, explorer),
|
||||
DecoratorModified:create(opts, explorer),
|
||||
DecoratorHidden:create(opts, explorer),
|
||||
DecoratorOpened:create(opts, explorer),
|
||||
DecoratorGit:create(opts, explorer),
|
||||
},
|
||||
hidden_display = Builder:setup_hidden_display_function(opts),
|
||||
}
|
||||
@@ -137,7 +137,7 @@ function Builder:unwrap_highlighted_strings(highlighted_strings)
|
||||
end
|
||||
|
||||
---@private
|
||||
---@param node table
|
||||
---@param node Node
|
||||
---@return HighlightedString icon
|
||||
---@return HighlightedString name
|
||||
function Builder:build_folder(node)
|
||||
@@ -189,7 +189,7 @@ function Builder:build_symlink(node)
|
||||
end
|
||||
|
||||
---@private
|
||||
---@param node table
|
||||
---@param node Node
|
||||
---@return HighlightedString icon
|
||||
---@return HighlightedString name
|
||||
function Builder:build_file(node)
|
||||
@@ -369,7 +369,7 @@ function Builder:build_line(node, idx, num_children)
|
||||
|
||||
self.index = self.index + 1
|
||||
|
||||
node = require("nvim-tree.lib").get_last_group_node(node)
|
||||
node = node:last_group_node()
|
||||
if node.open then
|
||||
self.depth = self.depth + 1
|
||||
self:build_lines(node)
|
||||
@@ -487,7 +487,7 @@ function Builder:build()
|
||||
return self
|
||||
end
|
||||
|
||||
---TODO refactor back to function; this was left here to reduce PR noise
|
||||
---@private
|
||||
---@param opts table
|
||||
---@return fun(node: Node): string|nil
|
||||
function Builder:setup_hidden_display_function(opts)
|
||||
|
||||
@@ -14,7 +14,7 @@ local M = {
|
||||
}
|
||||
|
||||
---Diagnostics highlight group and position when highlight_diagnostics.
|
||||
---@param node table
|
||||
---@param node Node
|
||||
---@return HL_POSITION position none when no status
|
||||
---@return string|nil group only when status
|
||||
function M.get_highlight(node)
|
||||
@@ -38,7 +38,7 @@ function M.get_highlight(node)
|
||||
end
|
||||
|
||||
---diagnostics icon if there is a status
|
||||
---@param node table
|
||||
---@param node Node
|
||||
---@return HighlightedString|nil modified icon
|
||||
function M.get_icon(node)
|
||||
if node and M.config.diagnostics.enable and M.config.renderer.icons.show.diagnostics then
|
||||
|
||||
@@ -59,7 +59,7 @@ end
|
||||
---@param depth integer
|
||||
---@param idx integer
|
||||
---@param nodes_number integer
|
||||
---@param node table
|
||||
---@param node Node
|
||||
---@param markers table
|
||||
---@return HighlightedString[]
|
||||
function M.get_indent_markers(depth, idx, nodes_number, node, markers, early_stop)
|
||||
@@ -79,7 +79,7 @@ function M.get_indent_markers(depth, idx, nodes_number, node, markers, early_sto
|
||||
return { str = str, hl = { "NvimTreeIndentMarker" } }
|
||||
end
|
||||
|
||||
---@param node table
|
||||
---@param node Node
|
||||
---@return HighlightedString[]|nil
|
||||
function M.get_arrows(node)
|
||||
if not M.config.icons.show.folder_arrow then
|
||||
|
||||
@@ -4,20 +4,22 @@ 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:new(opts, explorer)
|
||||
local o = Decorator.new(self, {
|
||||
function DecoratorBookmarks:create(opts, explorer)
|
||||
---@type DecoratorBookmarks
|
||||
local o = {
|
||||
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,
|
||||
})
|
||||
---@cast o DecoratorBookmarks
|
||||
}
|
||||
o = self:new(o) --[[@as DecoratorBookmarks]]
|
||||
|
||||
if opts.renderer.icons.show.bookmarks then
|
||||
o.icon = {
|
||||
|
||||
@@ -4,21 +4,22 @@ local ICON_PLACEMENT = require("nvim-tree.enum").ICON_PLACEMENT
|
||||
local Decorator = require("nvim-tree.renderer.decorator")
|
||||
|
||||
---@class (exact) DecoratorCopied: Decorator
|
||||
---@field enabled boolean
|
||||
---@field icon HighlightedString|nil
|
||||
---@field icon HighlightedString?
|
||||
local DecoratorCopied = Decorator:new()
|
||||
|
||||
---Static factory method
|
||||
---@param opts table
|
||||
---@param explorer Explorer
|
||||
---@return DecoratorCopied
|
||||
function DecoratorCopied:new(opts, explorer)
|
||||
local o = Decorator.new(self, {
|
||||
function DecoratorCopied:create(opts, explorer)
|
||||
---@type DecoratorCopied
|
||||
local o = {
|
||||
explorer = explorer,
|
||||
enabled = true,
|
||||
hl_pos = HL_POSITION[opts.renderer.highlight_clipboard] or HL_POSITION.none,
|
||||
icon_placement = ICON_PLACEMENT.none,
|
||||
})
|
||||
---@cast o DecoratorCopied
|
||||
}
|
||||
o = self:new(o) --[[@as DecoratorCopied]]
|
||||
|
||||
return o
|
||||
end
|
||||
|
||||
@@ -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:new(opts, explorer)
|
||||
local o = Decorator.new(self, {
|
||||
function DecoratorCut:create(opts, explorer)
|
||||
---@type DecoratorCut
|
||||
local o = {
|
||||
explorer = explorer,
|
||||
enabled = true,
|
||||
hl_pos = HL_POSITION[opts.renderer.highlight_clipboard] or HL_POSITION.none,
|
||||
icon_placement = ICON_PLACEMENT.none,
|
||||
})
|
||||
---@cast o DecoratorCut
|
||||
}
|
||||
o = self:new(o) --[[@as DecoratorCut]]
|
||||
|
||||
return o
|
||||
end
|
||||
|
||||
@@ -33,20 +33,22 @@ 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:new(opts, explorer)
|
||||
local o = Decorator.new(self, {
|
||||
function DecoratorDiagnostics:create(opts, explorer)
|
||||
---@type DecoratorDiagnostics
|
||||
local o = {
|
||||
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,
|
||||
})
|
||||
---@cast o DecoratorDiagnostics
|
||||
}
|
||||
o = self:new(o) --[[@as DecoratorDiagnostics]]
|
||||
|
||||
if not o.enabled then
|
||||
return o
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
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
|
||||
@@ -10,23 +9,25 @@ 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:new(opts, explorer)
|
||||
local o = Decorator.new(self, {
|
||||
function DecoratorGit:create(opts, explorer)
|
||||
---@type DecoratorGit
|
||||
local o = {
|
||||
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,
|
||||
})
|
||||
---@cast o DecoratorGit
|
||||
}
|
||||
o = self:new(o) --[[@as DecoratorGit]]
|
||||
|
||||
if not o.enabled then
|
||||
return o
|
||||
@@ -147,7 +148,7 @@ function DecoratorGit:calculate_icons(node)
|
||||
return nil
|
||||
end
|
||||
|
||||
local git_status = explorer_node.get_git_status(node)
|
||||
local git_status = node:get_git_status()
|
||||
if git_status == nil then
|
||||
return nil
|
||||
end
|
||||
@@ -208,7 +209,7 @@ function DecoratorGit:calculate_highlight(node)
|
||||
return nil
|
||||
end
|
||||
|
||||
local git_status = explorer_node.get_git_status(node)
|
||||
local git_status = node:get_git_status()
|
||||
if not git_status then
|
||||
return nil
|
||||
end
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
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|nil
|
||||
---@field icon HighlightedString?
|
||||
local DecoratorHidden = Decorator:new()
|
||||
|
||||
---Static factory method
|
||||
---@param opts table
|
||||
---@param explorer Explorer
|
||||
---@return DecoratorHidden
|
||||
function DecoratorHidden:new(opts, explorer)
|
||||
local o = Decorator.new(self, {
|
||||
function DecoratorHidden:create(opts, explorer)
|
||||
---@type DecoratorHidden
|
||||
local o = {
|
||||
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,
|
||||
})
|
||||
---@cast o DecoratorHidden
|
||||
}
|
||||
o = self:new(o) --[[@as DecoratorHidden]]
|
||||
|
||||
if opts.renderer.icons.show.hidden then
|
||||
o.icon = {
|
||||
@@ -34,7 +35,7 @@ end
|
||||
---@param node Node
|
||||
---@return HighlightedString[]|nil icons
|
||||
function DecoratorHidden:calculate_icons(node)
|
||||
if self.enabled and explorer_node.is_dotfile(node) then
|
||||
if self.enabled and node:is_dotfile() then
|
||||
return { self.icon }
|
||||
end
|
||||
end
|
||||
@@ -43,7 +44,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 explorer_node.is_dotfile(node)) then
|
||||
if not self.enabled or self.hl_pos == HL_POSITION.none or not node:is_dotfile() then
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
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
|
||||
|
||||
@@ -9,17 +9,19 @@ 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:new(opts, explorer)
|
||||
local o = Decorator.new(self, {
|
||||
function DecoratorModified:create(opts, explorer)
|
||||
---@type DecoratorModified
|
||||
local o = {
|
||||
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,
|
||||
})
|
||||
---@cast o DecoratorModified
|
||||
}
|
||||
o = self:new(o) --[[@as DecoratorModified]]
|
||||
|
||||
if not o.enabled then
|
||||
return o
|
||||
|
||||
@@ -6,21 +6,22 @@ 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:new(opts, explorer)
|
||||
local o = Decorator.new(self, {
|
||||
function DecoratorOpened:create(opts, explorer)
|
||||
---@type DecoratorOpened
|
||||
local o = {
|
||||
explorer = explorer,
|
||||
enabled = true,
|
||||
hl_pos = HL_POSITION[opts.renderer.highlight_opened_files] or HL_POSITION.none,
|
||||
icon_placement = ICON_PLACEMENT.none,
|
||||
})
|
||||
---@cast o DecoratorOpened
|
||||
}
|
||||
o = self:new(o) --[[@as DecoratorOpened]]
|
||||
|
||||
return o
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user