Skip to content

Commit f6392cf

Browse files
committed
typechecked optargs constructors for decorators
1 parent b092915 commit f6392cf

File tree

4 files changed

+59
-68
lines changed

4 files changed

+59
-68
lines changed

lua/nvim-tree/renderer/builder.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ local DecoratorCopied = require("nvim-tree.renderer.decorator.copied")
99
local DecoratorCut = require("nvim-tree.renderer.decorator.cut")
1010
local DecoratorDiagnostics = require("nvim-tree.renderer.decorator.diagnostics")
1111
local DecoratorGit = require("nvim-tree.renderer.decorator.git")
12-
-- local DecoratorModified = require("nvim-tree.renderer.decorator.modified")
13-
-- local DecoratorHidden = require("nvim-tree.renderer.decorator.hidden")
14-
-- local DecoratorOpened = require("nvim-tree.renderer.decorator.opened")
12+
local DecoratorModified = require("nvim-tree.renderer.decorator.modified")
13+
local DecoratorHidden = require("nvim-tree.renderer.decorator.hidden")
14+
local DecoratorOpened = require("nvim-tree.renderer.decorator.opened")
1515

1616
local pad = require("nvim-tree.renderer.components.padding")
1717

@@ -65,9 +65,9 @@ function Builder:new(opts, explorer)
6565
DecoratorCopied({ explorer = explorer }),
6666
DecoratorDiagnostics({ explorer = explorer }),
6767
DecoratorBookmarks({ explorer = explorer }),
68-
-- DecoratorModified({ explorer = explorer }),
69-
-- DecoratorHidden({ explorer = explorer }),
70-
-- DecoratorOpened({ explorer = explorer }),
68+
DecoratorModified({ explorer = explorer }),
69+
DecoratorHidden({ explorer = explorer }),
70+
DecoratorOpened({ explorer = explorer }),
7171
DecoratorGit({ explorer = explorer })
7272
},
7373
hidden_display = Builder:setup_hidden_display_function(opts),

lua/nvim-tree/renderer/decorator/hidden.lua

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,28 @@ local DirectoryNode = require("nvim-tree.node.directory")
66

77
---@class (exact) DecoratorHidden: Decorator
88
---@field icon HighlightedString?
9-
local DecoratorHidden = Decorator:new()
10-
11-
---Static factory method
12-
---@param opts table
13-
---@param explorer Explorer
14-
---@return DecoratorHidden
15-
function DecoratorHidden:create(opts, explorer)
16-
---@type DecoratorHidden
17-
local o = {
18-
explorer = explorer,
19-
enabled = true,
20-
hl_pos = HL_POSITION[opts.renderer.highlight_hidden] or HL_POSITION.none,
21-
icon_placement = ICON_PLACEMENT[opts.renderer.icons.hidden_placement] or ICON_PLACEMENT.none,
22-
}
23-
o = self:new(o)
24-
25-
if opts.renderer.icons.show.hidden then
26-
o.icon = {
27-
str = opts.renderer.icons.glyphs.hidden,
9+
local DecoratorHidden = Decorator:extend()
10+
11+
---@class DecoratorHidden
12+
---@overload fun(explorer: DecoratorArgs): DecoratorHidden
13+
14+
---@private
15+
---@param args DecoratorArgs
16+
function DecoratorHidden:new(args)
17+
Decorator.new(self, {
18+
explorer = args.explorer,
19+
enabled = true,
20+
hl_pos = HL_POSITION[args.explorer.opts.renderer.highlight_hidden] or HL_POSITION.none,
21+
icon_placement = ICON_PLACEMENT[args.explorer.opts.renderer.icons.hidden_placement] or ICON_PLACEMENT.none,
22+
})
23+
24+
if self.explorer.opts.renderer.icons.show.hidden then
25+
self.icon = {
26+
str = self.explorer.opts.renderer.icons.glyphs.hidden,
2827
hl = { "NvimTreeHiddenIcon" },
2928
}
30-
o:define_sign(o.icon)
29+
self:define_sign(self.icon)
3130
end
32-
33-
return o
3431
end
3532

3633
---Hidden icon: renderer.icons.show.hidden and node starts with `.` (dotfile).

lua/nvim-tree/renderer/decorator/modified.lua

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,33 @@ local Decorator = require("nvim-tree.renderer.decorator")
77
local DirectoryNode = require("nvim-tree.node.directory")
88

99
---@class (exact) DecoratorModified: Decorator
10-
---@field icon HighlightedString|nil
11-
local DecoratorModified = Decorator:new()
12-
13-
---Static factory method
14-
---@param opts table
15-
---@param explorer Explorer
16-
---@return DecoratorModified
17-
function DecoratorModified:create(opts, explorer)
18-
---@type DecoratorModified
19-
local o = {
20-
explorer = explorer,
21-
enabled = opts.modified.enable,
22-
hl_pos = HL_POSITION[opts.renderer.highlight_modified] or HL_POSITION.none,
23-
icon_placement = ICON_PLACEMENT[opts.renderer.icons.modified_placement] or ICON_PLACEMENT.none,
24-
}
25-
o = self:new(o)
26-
27-
if not o.enabled then
28-
return o
10+
---@field icon HighlightedString?
11+
local DecoratorModified = Decorator:extend()
12+
13+
---@class DecoratorModified
14+
---@overload fun(explorer: DecoratorArgs): DecoratorModified
15+
16+
---@private
17+
---@param args DecoratorArgs
18+
function DecoratorModified:new(args)
19+
Decorator.new(self, {
20+
explorer = args.explorer,
21+
enabled = true,
22+
hl_pos = HL_POSITION[args.explorer.opts.renderer.highlight_modified] or HL_POSITION.none,
23+
icon_placement = ICON_PLACEMENT[args.explorer.opts.renderer.icons.modified_placement] or ICON_PLACEMENT.none,
24+
})
25+
26+
if not self.enabled then
27+
return
2928
end
3029

31-
if opts.renderer.icons.show.modified then
32-
o.icon = {
33-
str = opts.renderer.icons.glyphs.modified,
30+
if self.explorer.opts.renderer.icons.show.modified then
31+
self.icon = {
32+
str = self.explorer.opts.renderer.icons.glyphs.modified,
3433
hl = { "NvimTreeModifiedIcon" },
3534
}
36-
o:define_sign(o.icon)
35+
self:define_sign(self.icon)
3736
end
38-
39-
return o
4037
end
4138

4239
---Modified icon: modified.enable, renderer.icons.show.modified and node is modified

lua/nvim-tree/renderer/decorator/opened.lua

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,20 @@ local Decorator = require("nvim-tree.renderer.decorator")
77

88
---@class (exact) DecoratorOpened: Decorator
99
---@field icon HighlightedString|nil
10-
local DecoratorOpened = Decorator:new()
10+
local DecoratorOpened = Decorator:extend()
1111

12-
---Static factory method
13-
---@param opts table
14-
---@param explorer Explorer
15-
---@return DecoratorOpened
16-
function DecoratorOpened:create(opts, explorer)
17-
---@type DecoratorOpened
18-
local o = {
19-
explorer = explorer,
20-
enabled = true,
21-
hl_pos = HL_POSITION[opts.renderer.highlight_opened_files] or HL_POSITION.none,
22-
icon_placement = ICON_PLACEMENT.none,
23-
}
24-
o = self:new(o)
12+
---@class DecoratorOpened
13+
---@overload fun(explorer: DecoratorArgs): DecoratorOpened
2514

26-
return o
15+
---@private
16+
---@param args DecoratorArgs
17+
function DecoratorOpened:new(args)
18+
Decorator.new(self, {
19+
explorer = args.explorer,
20+
enabled = true,
21+
hl_pos = HL_POSITION[args.explorer.opts.renderer.highlight_opened_files] or HL_POSITION.none,
22+
icon_placement = ICON_PLACEMENT.none,
23+
})
2724
end
2825

2926
---Opened highlight: renderer.highlight_opened_files and node has an open buffer

0 commit comments

Comments
 (0)