@@ -3,60 +3,56 @@ error("Cannot require a meta file")
3
3
4
4
local nvim_tree = { api = { decorator = { BaseDecorator = {} } } }
5
5
6
+ --- Create a custom decorator, extending nvim_tree.api.decorator.BaseDecorator
7
+ --- It may:
8
+ --- Add icons
9
+ --- Set name highlight group
10
+ --- Override node icon
11
+ --- Class must be created via nvim_tree.api.decorator.create()
12
+ --- Mandatory constructor :new() will be called once per tree render, with no arguments.
13
+ --- Constructor must call:
14
+ --- :init
15
+ --- :define_sign when using "signcolumn" range
16
+
6
17
--- Highlight group range as per nvim-tree.renderer.highlight_*
7
18
--- @alias nvim_tree.api.decorator.HighlightRange " none" | " icon" | " name" | " all"
8
19
9
20
--- Icon position as per renderer.icons.*_placement
10
21
--- @alias nvim_tree.api.decorator.IconPlacement " none" | " before" | " after" | " signcolumn" | " right_align"
11
22
12
- --
13
- -- BaseDecorator Class, see example implementation below
14
- --
23
+ --- Names of predefined decorators or your decorator classes
24
+ --- @alias nvim_tree.api.decorator.Name " Cut" | " Copied" | " Diagnostics" | " Bookmarks" | " Modified" | " Hidden" | " Opened" | " Git" | nvim_tree.api.decorator.BaseDecorator
15
25
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
26
+ --- BaseDecorator Class, your decorator will extend this
25
27
--- @class (exact ) nvim_tree.api.decorator.BaseDecorator
26
28
--- @field protected enabled boolean
27
29
--- @field protected highlight_range nvim_tree.api.decorator.HighlightRange
28
30
--- @field protected icon_placement nvim_tree.api.decorator.IconPlacement
29
31
30
- --- Constructor Arguments
31
- --- @class (exact ) nvim_tree.api.decorator.BaseDecoratorArgs
32
+ --- No-args constructor must be implemented
33
+ function nvim_tree .api .decorator .BaseDecorator :new () end
34
+
35
+ --- Must be called from your constructor
36
+ --- @class (exact ) nvim_tree.api.decorator.InitArgs
32
37
--- @field enabled boolean
33
38
--- @field highlight_range nvim_tree.api.decorator.HighlightRange
34
39
--- @field icon_placement nvim_tree.api.decorator.IconPlacement
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)
40
+ ---
41
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
42
+ --- @param args nvim_tree.api.decorator.InitArgs
43
+ function nvim_tree .api .decorator .BaseDecorator :init (args ) end
45
44
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
45
+ --- Optionally implement this method to set the node's icon
50
46
--- @param node nvim_tree.api.Node
51
47
--- @return HighlightedString ? icon_node
52
48
function nvim_tree .api .decorator .BaseDecorator :icon_node (node ) end
53
49
54
- --- Implement this method to provide icons and the highlight groups to apply to IconPlacement
50
+ --- Optionally implement this method to provide icons and the highlight groups for your icon_placement
55
51
--- @param node nvim_tree.api.Node
56
52
--- @return HighlightedString[] ? icons
57
53
function nvim_tree .api .decorator .BaseDecorator :icons (node ) end
58
54
59
- --- Implement this method to provide one highlight group to apply to HighlightRange
55
+ --- Optionally implement this method to provide one highlight group to apply to your highlight_range
60
56
--- @param node nvim_tree.api.Node
61
57
--- @return string ? highlight_group
62
58
function nvim_tree .api .decorator .BaseDecorator :highlight_group (node ) end
@@ -65,23 +61,21 @@ function nvim_tree.api.decorator.BaseDecorator:highlight_group(node) end
65
61
-- Example Decorator
66
62
--
67
63
68
- local BaseDecorator = require (" nvim-tree.api" ).decorator .BaseDecorator
69
-
70
64
--- @class (exact ) MyDecorator : nvim_tree.api.decorator.BaseDecorator
71
65
--- @field private my_icon nvim_tree.api.HighlightedString
72
- local MyDecorator = BaseDecorator : extend ()
66
+ local MyDecorator = require ( " nvim-tree.api " ). decorator . create ()
73
67
74
68
--- Mandatory constructor :new() will be called once per tree render, with no arguments.
75
69
function MyDecorator :new ()
76
- ---- @type nvim_tree.api.decorator.BaseDecoratorArgs
70
+ --- @type nvim_tree.api.decorator.InitArgs
77
71
local args = {
78
72
enabled = true ,
79
73
highlight_range = " all" ,
80
74
icon_placement = " signcolumn" ,
81
75
}
82
76
83
- -- construct super with args
84
- BaseDecorator . new ( self , args )
77
+ -- init
78
+ self : init ( args )
85
79
86
80
-- create your icon once, for convenience
87
81
self .my_icon = { str = " I" , hl = { " MyIcon" } }
0 commit comments