@@ -2,6 +2,7 @@ local notify = require("nvim-tree.notify")
2
2
local utils = require (" nvim-tree.utils" )
3
3
local view = require (" nvim-tree.view" )
4
4
5
+ local Class = require (" nvim-tree.classic" )
5
6
local DirectoryNode = require (" nvim-tree.node.directory" )
6
7
7
8
local DecoratorBookmarks = require (" nvim-tree.renderer.decorator.bookmarks" )
@@ -33,50 +34,44 @@ local pad = require("nvim-tree.renderer.components.padding")
33
34
--- @field extmarks table[] extra marks for right icon placement
34
35
--- @field virtual_lines table[] virtual lines for hidden count display
35
36
--- @field private explorer Explorer
36
- --- @field private opts table
37
37
--- @field private index number
38
38
--- @field private depth number
39
39
--- @field private combined_groups table<string , boolean> combined group names
40
40
--- @field private markers boolean[] indent markers
41
41
--- @field private decorators Decorator[]
42
42
--- @field private hidden_display fun (node : Node ): string | nil
43
- local Builder = {}
44
-
45
- --- @param opts table user options
46
- --- @param explorer Explorer
47
- --- @return Builder
48
- function Builder :new (opts , explorer )
49
- --- @type Builder
50
- local o = {
51
- opts = opts ,
52
- explorer = explorer ,
53
- index = 0 ,
54
- depth = 0 ,
55
- hl_args = {},
56
- combined_groups = {},
57
- lines = {},
58
- markers = {},
59
- signs = {},
60
- extmarks = {},
61
- virtual_lines = {},
62
- decorators = {
63
- -- priority order
64
- DecoratorCut ({ explorer = explorer }),
65
- DecoratorCopied ({ explorer = explorer }),
66
- DecoratorDiagnostics ({ explorer = explorer }),
67
- DecoratorBookmarks ({ explorer = explorer }),
68
- DecoratorModified ({ explorer = explorer }),
69
- DecoratorHidden ({ explorer = explorer }),
70
- DecoratorOpened ({ explorer = explorer }),
71
- DecoratorGit ({ explorer = explorer })
72
- },
73
- hidden_display = Builder :setup_hidden_display_function (opts ),
43
+ local Builder = Class :extend ()
44
+
45
+ --- @class Builder
46
+ --- @overload fun ( args : BuilderArgs ): Builder
47
+
48
+ --- @class (exact ) BuilderArgs
49
+ --- @field explorer Explorer
50
+
51
+ --- @param args BuilderArgs
52
+ function Builder :new (args )
53
+ self .explorer = args .explorer
54
+ self .index = 0
55
+ self .depth = 0
56
+ self .hl_args = {}
57
+ self .combined_groups = {}
58
+ self .lines = {}
59
+ self .markers = {}
60
+ self .signs = {}
61
+ self .extmarks = {}
62
+ self .virtual_lines = {}
63
+ self .decorators = {
64
+ -- priority order
65
+ DecoratorCut ({ explorer = args .explorer }),
66
+ DecoratorCopied ({ explorer = args .explorer }),
67
+ DecoratorDiagnostics ({ explorer = args .explorer }),
68
+ DecoratorBookmarks ({ explorer = args .explorer }),
69
+ DecoratorModified ({ explorer = args .explorer }),
70
+ DecoratorHidden ({ explorer = args .explorer }),
71
+ DecoratorOpened ({ explorer = args .explorer }),
72
+ DecoratorGit ({ explorer = args .explorer })
74
73
}
75
-
76
- setmetatable (o , self )
77
- self .__index = self
78
-
79
- return o
74
+ self .hidden_display = Builder :setup_hidden_display_function (args .explorer .opts )
80
75
end
81
76
82
77
--- Insert ranged highlight groups into self.highlights
@@ -123,7 +118,7 @@ function Builder:format_line(indent_markers, arrows, icon, name, node)
123
118
end
124
119
for _ , v in ipairs (t2 ) do
125
120
if added_len > 0 then
126
- table.insert (t1 , { str = self .opts .renderer .icons .padding })
121
+ table.insert (t1 , { str = self .explorer . opts .renderer .icons .padding })
127
122
end
128
123
table.insert (t1 , v )
129
124
end
@@ -284,7 +279,7 @@ function Builder:add_hidden_count_string(node, idx, num_children)
284
279
local hidden_count_string = self .hidden_display (node .hidden_stats )
285
280
if hidden_count_string and hidden_count_string ~= " " then
286
281
local indent_markers = pad .get_indent_markers (self .depth , idx or 0 , num_children or 0 , node , self .markers , 1 )
287
- local indent_width = self .opts .renderer .indent_width
282
+ local indent_width = self .explorer . opts .renderer .indent_width
288
283
289
284
local indent_padding = string.rep (" " , indent_width )
290
285
local indent_string = indent_padding .. indent_markers .str
@@ -354,16 +349,16 @@ end
354
349
--- @private
355
350
function Builder :build_header ()
356
351
if view .is_root_folder_visible (self .explorer .absolute_path ) then
357
- local root_name = self :format_root_name (self .opts .renderer .root_folder_label )
352
+ local root_name = self :format_root_name (self .explorer . opts .renderer .root_folder_label )
358
353
table.insert (self .lines , root_name )
359
354
self :insert_highlight ({ " NvimTreeRootFolder" }, 0 , string.len (root_name ))
360
355
self .index = 1
361
356
end
362
357
363
358
if self .explorer .live_filter .filter then
364
- local filter_line = string.format (" %s/%s/" , self .opts .live_filter .prefix , self .explorer .live_filter .filter )
359
+ local filter_line = string.format (" %s/%s/" , self .explorer . opts .live_filter .prefix , self .explorer .live_filter .filter )
365
360
table.insert (self .lines , filter_line )
366
- local prefix_length = string.len (self .opts .live_filter .prefix )
361
+ local prefix_length = string.len (self .explorer . opts .live_filter .prefix )
367
362
self :insert_highlight ({ " NvimTreeLiveFilterPrefix" }, 0 , prefix_length )
368
363
self :insert_highlight ({ " NvimTreeLiveFilterValue" }, prefix_length , string.len (filter_line ))
369
364
self .index = self .index + 1
0 commit comments