typechecked optargs constructors for decorators
This commit is contained in:
parent
b092915f17
commit
f6392cf88a
@ -9,9 +9,9 @@ local DecoratorCopied = require("nvim-tree.renderer.decorator.copied")
|
||||
local DecoratorCut = require("nvim-tree.renderer.decorator.cut")
|
||||
local DecoratorDiagnostics = require("nvim-tree.renderer.decorator.diagnostics")
|
||||
local DecoratorGit = require("nvim-tree.renderer.decorator.git")
|
||||
-- local DecoratorModified = require("nvim-tree.renderer.decorator.modified")
|
||||
-- local DecoratorHidden = require("nvim-tree.renderer.decorator.hidden")
|
||||
-- local DecoratorOpened = require("nvim-tree.renderer.decorator.opened")
|
||||
local DecoratorModified = require("nvim-tree.renderer.decorator.modified")
|
||||
local DecoratorHidden = require("nvim-tree.renderer.decorator.hidden")
|
||||
local DecoratorOpened = require("nvim-tree.renderer.decorator.opened")
|
||||
|
||||
local pad = require("nvim-tree.renderer.components.padding")
|
||||
|
||||
@ -65,9 +65,9 @@ function Builder:new(opts, explorer)
|
||||
DecoratorCopied({ explorer = explorer }),
|
||||
DecoratorDiagnostics({ explorer = explorer }),
|
||||
DecoratorBookmarks({ explorer = explorer }),
|
||||
-- DecoratorModified({ explorer = explorer }),
|
||||
-- DecoratorHidden({ explorer = explorer }),
|
||||
-- DecoratorOpened({ explorer = explorer }),
|
||||
DecoratorModified({ explorer = explorer }),
|
||||
DecoratorHidden({ explorer = explorer }),
|
||||
DecoratorOpened({ explorer = explorer }),
|
||||
DecoratorGit({ explorer = explorer })
|
||||
},
|
||||
hidden_display = Builder:setup_hidden_display_function(opts),
|
||||
|
||||
@ -6,31 +6,28 @@ local DirectoryNode = require("nvim-tree.node.directory")
|
||||
|
||||
---@class (exact) DecoratorHidden: Decorator
|
||||
---@field icon HighlightedString?
|
||||
local DecoratorHidden = Decorator:new()
|
||||
local DecoratorHidden = Decorator:extend()
|
||||
|
||||
---Static factory method
|
||||
---@param opts table
|
||||
---@param explorer Explorer
|
||||
---@return DecoratorHidden
|
||||
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,
|
||||
}
|
||||
o = self:new(o)
|
||||
---@class DecoratorHidden
|
||||
---@overload fun(explorer: DecoratorArgs): DecoratorHidden
|
||||
|
||||
if opts.renderer.icons.show.hidden then
|
||||
o.icon = {
|
||||
str = opts.renderer.icons.glyphs.hidden,
|
||||
---@private
|
||||
---@param args DecoratorArgs
|
||||
function DecoratorHidden:new(args)
|
||||
Decorator.new(self, {
|
||||
explorer = args.explorer,
|
||||
enabled = true,
|
||||
hl_pos = HL_POSITION[args.explorer.opts.renderer.highlight_hidden] or HL_POSITION.none,
|
||||
icon_placement = ICON_PLACEMENT[args.explorer.opts.renderer.icons.hidden_placement] or ICON_PLACEMENT.none,
|
||||
})
|
||||
|
||||
if self.explorer.opts.renderer.icons.show.hidden then
|
||||
self.icon = {
|
||||
str = self.explorer.opts.renderer.icons.glyphs.hidden,
|
||||
hl = { "NvimTreeHiddenIcon" },
|
||||
}
|
||||
o:define_sign(o.icon)
|
||||
self:define_sign(self.icon)
|
||||
end
|
||||
|
||||
return o
|
||||
end
|
||||
|
||||
---Hidden icon: renderer.icons.show.hidden and node starts with `.` (dotfile).
|
||||
|
||||
@ -7,36 +7,33 @@ local Decorator = require("nvim-tree.renderer.decorator")
|
||||
local DirectoryNode = require("nvim-tree.node.directory")
|
||||
|
||||
---@class (exact) DecoratorModified: Decorator
|
||||
---@field icon HighlightedString|nil
|
||||
local DecoratorModified = Decorator:new()
|
||||
---@field icon HighlightedString?
|
||||
local DecoratorModified = Decorator:extend()
|
||||
|
||||
---Static factory method
|
||||
---@param opts table
|
||||
---@param explorer Explorer
|
||||
---@return DecoratorModified
|
||||
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,
|
||||
}
|
||||
o = self:new(o)
|
||||
---@class DecoratorModified
|
||||
---@overload fun(explorer: DecoratorArgs): DecoratorModified
|
||||
|
||||
if not o.enabled then
|
||||
return o
|
||||
---@private
|
||||
---@param args DecoratorArgs
|
||||
function DecoratorModified:new(args)
|
||||
Decorator.new(self, {
|
||||
explorer = args.explorer,
|
||||
enabled = true,
|
||||
hl_pos = HL_POSITION[args.explorer.opts.renderer.highlight_modified] or HL_POSITION.none,
|
||||
icon_placement = ICON_PLACEMENT[args.explorer.opts.renderer.icons.modified_placement] or ICON_PLACEMENT.none,
|
||||
})
|
||||
|
||||
if not self.enabled then
|
||||
return
|
||||
end
|
||||
|
||||
if opts.renderer.icons.show.modified then
|
||||
o.icon = {
|
||||
str = opts.renderer.icons.glyphs.modified,
|
||||
if self.explorer.opts.renderer.icons.show.modified then
|
||||
self.icon = {
|
||||
str = self.explorer.opts.renderer.icons.glyphs.modified,
|
||||
hl = { "NvimTreeModifiedIcon" },
|
||||
}
|
||||
o:define_sign(o.icon)
|
||||
self:define_sign(self.icon)
|
||||
end
|
||||
|
||||
return o
|
||||
end
|
||||
|
||||
---Modified icon: modified.enable, renderer.icons.show.modified and node is modified
|
||||
|
||||
@ -7,23 +7,20 @@ local Decorator = require("nvim-tree.renderer.decorator")
|
||||
|
||||
---@class (exact) DecoratorOpened: Decorator
|
||||
---@field icon HighlightedString|nil
|
||||
local DecoratorOpened = Decorator:new()
|
||||
local DecoratorOpened = Decorator:extend()
|
||||
|
||||
---Static factory method
|
||||
---@param opts table
|
||||
---@param explorer Explorer
|
||||
---@return DecoratorOpened
|
||||
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,
|
||||
---@class DecoratorOpened
|
||||
---@overload fun(explorer: DecoratorArgs): DecoratorOpened
|
||||
|
||||
---@private
|
||||
---@param args DecoratorArgs
|
||||
function DecoratorOpened:new(args)
|
||||
Decorator.new(self, {
|
||||
explorer = args.explorer,
|
||||
enabled = true,
|
||||
hl_pos = HL_POSITION[args.explorer.opts.renderer.highlight_opened_files] or HL_POSITION.none,
|
||||
icon_placement = ICON_PLACEMENT.none,
|
||||
}
|
||||
o = self:new(o)
|
||||
|
||||
return o
|
||||
})
|
||||
end
|
||||
|
||||
---Opened highlight: renderer.highlight_opened_files and node has an open buffer
|
||||
|
||||
Loading…
Reference in New Issue
Block a user