11--- @meta
22error (' Cannot require a meta file' )
33
4+ local nvim_tree = { api = { decorator = { BaseDecorator = {} } } }
5+
46--- Highlight group range as per nvim-tree.renderer.highlight_*
57--- @alias nvim_tree.api.decorator.HighlightRange " none" | " icon" | " name" | " all"
68
79--- Icon position as per renderer.icons.*_placement
810--- @alias nvim_tree.api.decorator.IconPlacement " none" | " before" | " after" | " signcolumn" | " right_align"
911
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
1232--- @field enabled boolean
1333--- @field highlight_range nvim_tree.api.decorator.HighlightRange
1434--- @field icon_placement nvim_tree.api.decorator.IconPlacement
1535
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+
1664
1765--
18- -- Example UserDecorator
66+ -- Example Decorator
1967--
2068
21- local UserDecorator = require (" nvim-tree.renderer .decorator.user " )
69+ local BaseDecorator = require (" nvim-tree.api " ) .decorator .BaseDecorator
2270
23- --- @class (exact ) MyDecorator : UserDecorator
71+ --- @class (exact ) MyDecorator : nvim_tree.api.decorator.BaseDecorator
2472--- @field private my_icon nvim_tree.api.HighlightedString
25- local MyDecorator = UserDecorator :extend ()
73+ local MyDecorator = BaseDecorator :extend ()
2674
27- --- Constructor
75+ --- Mandatory constructor :new() will be called once per tree render, with no arguments.
2876function MyDecorator :new ()
29-
30- --- @type nvim_tree.api.decorator.UserDecoratorArgs
77+ ---- @type nvim_tree.api.decorator.BaseDecoratorArgs
3178 local args = {
3279 enabled = true ,
3380 highlight_range = " all" ,
3481 icon_placement = " signcolumn" ,
3582 }
3683
3784 -- construct super with args
38- MyDecorator . super .new (self , args )
85+ BaseDecorator .new (self , args )
3986
4087 -- create your icon once, for convenience
4188 self .my_icon = { str = " I" , hl = { " MyIcon" } }
@@ -45,7 +92,7 @@ function MyDecorator:new()
4592 self :define_sign (self .my_icon )
4693end
4794
48- --- Overridde node icon
95+ --- Override node icon
4996--- @param node nvim_tree.api.Node
5097--- @return nvim_tree.api.HighlightedString ? icon_node
5198function MyDecorator :icon_node (node )
@@ -79,10 +126,3 @@ function MyDecorator:highlight_group(node)
79126end
80127
81128return 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