Skip to content

Commit 8b5f342

Browse files
committed
feat(#2948): document API
1 parent 93cf3f9 commit 8b5f342

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

lua/nvim-tree/_meta/api_decorator.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ error("Cannot require a meta file")
33

44
local nvim_tree = { api = { decorator = { BaseDecorator = {} } } }
55

6-
---Create a custom decorator, extending nvim_tree.api.decorator.BaseDecorator
6+
---Custom decorator extends nvim_tree.api.decorator.BaseDecorator
77
---It may:
88
--- Add icons
99
--- Set name highlight group
@@ -24,15 +24,18 @@ local nvim_tree = { api = { decorator = { BaseDecorator = {} } } }
2424
---@alias nvim_tree.api.decorator.Name "Cut" | "Copied" | "Diagnostics" | "Bookmarks" | "Modified" | "Hidden" | "Opened" | "Git" | nvim_tree.api.decorator.BaseDecorator
2525

2626
---BaseDecorator Class, your decorator will extend this
27+
---
2728
---@class (exact) nvim_tree.api.decorator.BaseDecorator
2829
---@field protected enabled boolean
2930
---@field protected highlight_range nvim_tree.api.decorator.HighlightRange
3031
---@field protected icon_placement nvim_tree.api.decorator.IconPlacement
3132

3233
---No-args constructor must be implemented
34+
---
3335
function nvim_tree.api.decorator.BaseDecorator:new() end
3436

3537
---Must be called from your constructor
38+
---
3639
---@class (exact) nvim_tree.api.decorator.InitArgs
3740
---@field enabled boolean
3841
---@field highlight_range nvim_tree.api.decorator.HighlightRange
@@ -43,20 +46,24 @@ function nvim_tree.api.decorator.BaseDecorator:new() end
4346
function nvim_tree.api.decorator.BaseDecorator:init(args) end
4447

4548
---Optionally implement this method to set the node's icon
49+
---
4650
---@param node nvim_tree.api.Node
4751
---@return HighlightedString? icon_node
4852
function nvim_tree.api.decorator.BaseDecorator:icon_node(node) end
4953

5054
---Optionally implement this method to provide icons and the highlight groups for your icon_placement
55+
---
5156
---@param node nvim_tree.api.Node
5257
---@return HighlightedString[]? icons
5358
function nvim_tree.api.decorator.BaseDecorator:icons(node) end
5459

5560
---Optionally implement this method to provide one highlight group to apply to your highlight_range
61+
---
5662
---@param node nvim_tree.api.Node
5763
---@return string? highlight_group
5864
function nvim_tree.api.decorator.BaseDecorator:highlight_group(node) end
5965

66+
6067
--
6168
-- Example Decorator
6269
--

lua/nvim-tree/renderer/builder.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@ function Builder:new(args)
4949
self.signs = {}
5050
self.extmarks = {}
5151
self.virtual_lines = {}
52+
self.decorators = {}
5253
self.hidden_display = Builder:setup_hidden_display_function(self.explorer.opts)
5354

54-
-- lowest priority is registered first
55-
self.decorators = {}
55+
---@type DecoratorArgs
5656
local decorator_args = { explorer = self.explorer }
57+
58+
-- lowest priority is registered first
5759
for _, d in ipairs(decorator_registry.registered) do
5860
if d:is(DecoratorUser) then
5961
table.insert(self.decorators, 1, d())

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ local Decorator = Class:extend()
1010

1111
---@class (exact) DecoratorArgs
1212
---@field explorer Explorer
13-
---
13+
14+
---Abstract constructor
1415
---@class (exact) AbstractDecoratorArgs
1516
---@field enabled boolean
1617
---@field highlight_range DecoratorHighlightRange
1718
---@field icon_placement DecoratorIconPlacement
18-
19+
---
1920
---@protected
2021
---@param args AbstractDecoratorArgs
2122
function Decorator:new(args)

0 commit comments

Comments
 (0)