1
1
--- @meta
2
2
error (' Cannot require a meta file' )
3
3
4
+ local nvim_tree = { api = { decorator = { BaseDecorator = {} } } }
5
+
4
6
--- Highlight group range as per nvim-tree.renderer.highlight_*
5
7
--- @alias nvim_tree.api.decorator.HighlightRange " none" | " icon" | " name" | " all"
6
8
7
9
--- Icon position as per renderer.icons.*_placement
8
10
--- @alias nvim_tree.api.decorator.IconPlacement " none" | " before" | " after" | " signcolumn" | " right_align"
9
11
10
- --- UserDecorator Constructor Arguments
11
- --- @class (exact ) nvim_tree.api.decorator.UserDecoratorArgs
12
+ --
13
+ -- BaseDecorator Class, see example implementation below
14
+ --
15
+
16
+ --- User defined decorator to optionally add:
17
+ --- Additional icons
18
+ --- Name highlight group
19
+ --- Node icon override
20
+ --- Class must be created via nvim_tree.api.decorator.BaseDecorator:extend()
21
+ --- Mandatory constructor :new() will be called once per tree render, with no arguments.
22
+ --- Constructor must call:
23
+ --- .super.new(self, args) passing nvim_tree.api.decorator.BaseDecoratorArgs
24
+ --- :define_sign(...) when using "signcolumn" range
25
+ --- @class (exact ) nvim_tree.api.decorator.BaseDecorator
26
+ --- @field protected enabled boolean
27
+ --- @field protected highlight_range nvim_tree.api.decorator.HighlightRange
28
+ --- @field protected icon_placement nvim_tree.api.decorator.IconPlacement
29
+
30
+ --- Constructor Arguments
31
+ --- @class (exact ) nvim_tree.api.decorator.BaseDecoratorArgs
12
32
--- @field enabled boolean
13
33
--- @field highlight_range nvim_tree.api.decorator.HighlightRange
14
34
--- @field icon_placement nvim_tree.api.decorator.IconPlacement
15
35
36
+ --- Use to instantiate your decorator class
37
+ function nvim_tree .api .decorator .BaseDecorator :extend () end
38
+
39
+ --- Super constructor must be called from your constructor
40
+ --- BaseDecorator.super.new(self, args)
41
+ --- @protected
42
+ --- @param self nvim_tree.api.decorator.BaseDecorator your instance
43
+ --- @param args nvim_tree.api.decorator.BaseDecoratorArgs
44
+ function nvim_tree .api .decorator .BaseDecorator .new (self , args ) end
45
+
46
+ --- Must implement a constructor and call super
47
+ function nvim_tree .api .decorator .BaseDecorator :new () end
48
+
49
+ --- Implement this method to set the node's icon
50
+ --- @param node nvim_tree.api.Node
51
+ --- @return HighlightedString ? icon_node
52
+ function nvim_tree .api .decorator .BaseDecorator :icon_node (node ) end
53
+
54
+ --- Implement this method to provide icons and the highlight groups to apply to IconPlacement
55
+ --- @param node nvim_tree.api.Node
56
+ --- @return HighlightedString[] ? icons
57
+ function nvim_tree .api .decorator .BaseDecorator :icons (node ) end
58
+
59
+ --- Implement this method to provide one highlight group to apply to HighlightRange
60
+ --- @param node nvim_tree.api.Node
61
+ --- @return string ? highlight_group
62
+ function nvim_tree .api .decorator .BaseDecorator :highlight_group (node ) end
63
+
16
64
17
65
--
18
- -- Example UserDecorator
66
+ -- Example Decorator
19
67
--
20
68
21
- local UserDecorator = require (" nvim-tree.renderer .decorator.user " )
69
+ local BaseDecorator = require (" nvim-tree.api " ) .decorator .BaseDecorator
22
70
23
- --- @class (exact ) MyDecorator : UserDecorator
71
+ --- @class (exact ) MyDecorator : nvim_tree.api.decorator.BaseDecorator
24
72
--- @field private my_icon nvim_tree.api.HighlightedString
25
- local MyDecorator = UserDecorator :extend ()
73
+ local MyDecorator = BaseDecorator :extend ()
26
74
27
- --- Constructor
75
+ --- Mandatory constructor :new() will be called once per tree render, with no arguments.
28
76
function MyDecorator :new ()
29
-
30
- --- @type nvim_tree.api.decorator.UserDecoratorArgs
77
+ ---- @type nvim_tree.api.decorator.BaseDecoratorArgs
31
78
local args = {
32
79
enabled = true ,
33
80
highlight_range = " all" ,
34
81
icon_placement = " signcolumn" ,
35
82
}
36
83
37
84
-- construct super with args
38
- MyDecorator . super .new (self , args )
85
+ BaseDecorator .new (self , args )
39
86
40
87
-- create your icon once, for convenience
41
88
self .my_icon = { str = " I" , hl = { " MyIcon" } }
@@ -45,7 +92,7 @@ function MyDecorator:new()
45
92
self :define_sign (self .my_icon )
46
93
end
47
94
48
- --- Overridde node icon
95
+ --- Override node icon
49
96
--- @param node nvim_tree.api.Node
50
97
--- @return nvim_tree.api.HighlightedString ? icon_node
51
98
function MyDecorator :icon_node (node )
@@ -79,10 +126,3 @@ function MyDecorator:highlight_group(node)
79
126
end
80
127
81
128
return MyDecorator
82
-
83
- --
84
- -- Internal Aliases
85
- --
86
- --- @alias DecoratorHighlightRange nvim_tree.api.decorator.HighlightRange
87
- --- @alias DecoratorIconPlacement nvim_tree.api.decorator.IconPlacement
88
-
0 commit comments