Skip to content

Commit 3e7b376

Browse files
committed
docs(#3241): nvim-tree-api-decorator brief
1 parent 58d4b2a commit 3e7b376

5 files changed

Lines changed: 72 additions & 6 deletions

File tree

doc/nvim-tree-lua.txt

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ for files and and directories.
487487
Highlighting is additive, with higher precedence overriding lower.
488488

489489
|nvim_tree.config.renderer| {decorators} controls which highlighting is
490-
applied and its precedence. See |nvim-tree-decorators| for information on
490+
applied and its precedence. See |nvim-tree-api-decorator| for information on
491491
creating custom decorators.
492492
<
493493
`ICON`
@@ -1366,9 +1366,10 @@ Config: renderer *nvim-tree-config-renderer*
13661366
• {symlink_destination}? (`boolean`, default: `true`) Appends an
13671367
arrow followed by the target of the
13681368
symlink.
1369-
{decorators}? (`(string|nvim_tree.api.Decorator)[]`)
1370-
(default:
1371-
`{ "Git", "Open", "Hidden", "Modified", "Bookmark", "Diagnostics", "Copied", "Cut", }`)
1369+
{decorators}? (`(string|nvim_tree.api.Decorator)[]`, default: `{ "Git", "Open", "Hidden", "Modified", "Bookmark", "Diagnostics", "Copied", "Cut", }`)
1370+
Ordered list of builtin and user decorators
1371+
to enable, see |nvim-tree-api-decorator|
1372+
and |nvim-tree-icons-highlighting|
13721373
• {highlight_git}? (`nvim_tree.config.renderer.highlight`)
13731374
(default: `"none"`)
13741375
• {highlight_opened_files}? (`nvim_tree.config.renderer.highlight`)
@@ -3203,6 +3204,38 @@ winid({opts}) *nvim_tree.api.tree.winid()*
32033204
==============================================================================
32043205
API: Decorator *nvim-tree-api-decorator*
32053206

3207+
Highlighting and icons for nodes are provided by Decorators, see
3208+
|nvim-tree-icons-highlighting|. You may provide your own in addition to the
3209+
builtin decorators.
3210+
3211+
Decorators may:
3212+
• Add icons
3213+
• Set highlight group for the name or icons
3214+
• Override node icon
3215+
3216+
To register your decorator:
3217+
• Create a class that extends |nvim_tree.api.Decorator|
3218+
• Register it by adding the class to |nvim_tree.config.renderer| {decorators}
3219+
3220+
Your class must:
3221+
|nvim_tree.Class:extend()| the interface |nvim_tree.api.Decorator|
3222+
• Provide a no-arguments constructor |nvim_tree.Class:new()| that sets the
3223+
mandatory fields:
3224+
{enabled}
3225+
• {highlight_range}
3226+
• {icon_placement}
3227+
3228+
Your class may:
3229+
• Implement methods to provide decorations:
3230+
|nvim_tree.api.Decorator:highlight_group()|
3231+
|nvim_tree.api.Decorator:icon_node()|
3232+
|nvim_tree.api.Decorator:icons()|
3233+
3234+
Your class must:
3235+
• Call |nvim_tree.api.Decorator:define_sign()| in your constructor if using
3236+
`"signcolumn"` {icon_placement}
3237+
3238+
32063239
*nvim_tree.api.Decorator*
32073240
Extends: |nvim_tree.Class|
32083241

@@ -3266,6 +3299,8 @@ API: Class *nvim-tree-api-class*
32663299

32673300
Fields: ~
32683301
{super} (`Class`)
3302+
{new} (`fun(self: nvim_tree.Class)`) See
3303+
|nvim_tree.Class:new()|.
32693304
{extend} (`fun(self: nvim_tree.Class)`) See
32703305
|nvim_tree.Class:extend()|.
32713306
{implement} (`fun(self: nvim_tree.Class, mixin: Class)`) See
@@ -3305,6 +3340,9 @@ Class:is({class}) *nvim_tree.Class:is()*
33053340
Return: ~
33063341
(`boolean`)
33073342

3343+
Class:new() *nvim_tree.Class:new()*
3344+
Default constructor
3345+
33083346
Class:nop({...}) *nvim_tree.Class:nop()*
33093347

33103348
Parameters: ~

lua/nvim-tree/_meta/api/decorator.lua

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,33 @@
11
---@meta
2+
3+
---@brief
4+
---Highlighting and icons for nodes are provided by Decorators, see [nvim-tree-icons-highlighting]. You may provide your own in addition to the builtin decorators.
5+
---
6+
---Decorators may:
7+
---- Add icons
8+
---- Set highlight group for the name or icons
9+
---- Override node icon
10+
---
11+
---To register your decorator:
12+
---- Create a class that extends [nvim_tree.api.Decorator]
13+
---- Register it by adding the class to [nvim_tree.config.renderer] {decorators}
14+
---
15+
---Your class must:
16+
---- [nvim_tree.Class:extend()] the interface [nvim_tree.api.Decorator]
17+
---- Provide a no-arguments constructor [nvim_tree.Class:new()] that sets the mandatory fields:
18+
--- - {enabled}
19+
--- - {highlight_range}
20+
--- - {icon_placement}
21+
---
22+
---Your class may:
23+
---- Implement methods to provide decorations:
24+
--- - [nvim_tree.api.Decorator:highlight_group()]
25+
--- - [nvim_tree.api.Decorator:icon_node()]
26+
--- - [nvim_tree.api.Decorator:icons()]
27+
---
28+
---Your class must:
29+
---- Call [nvim_tree.api.Decorator:define_sign()] in your constructor if using `"signcolumn"` {icon_placement}
30+
231
local nvim_tree = { api = {} }
332

433
local Class = require("nvim-tree.classic")

lua/nvim-tree/_meta/config/renderer.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ error("Cannot require a meta file")
6161
---(default: `true`)
6262
---@field symlink_destination? boolean
6363
---
64+
---Ordered list of builtin and user decorators to enable, see [nvim-tree-api-decorator] and [nvim-tree-icons-highlighting]
6465
---(default: `{ "Git", "Open", "Hidden", "Modified", "Bookmark", "Diagnostics", "Copied", "Cut", }`)
6566
---@field decorators? (string|nvim_tree.api.Decorator)[]
6667
---

lua/nvim-tree/classic.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ local Class = {}
2020
Class.__index = Class ---@diagnostic disable-line: inject-field
2121

2222
---Default constructor
23-
---@protected
2423
function Class:new(...) --luacheck: ignore 212
2524
end
2625

scripts/vimdoc_config.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ return {
157157

158158
-- strip module from name and record the module for the method
159159
modules_by_method[fun.classvar .. ":" .. fun.name] = fun.module
160-
print(vim.inspect(modules_by_method))
161160
end,
162161

163162
-- fn_helptag_fmt_common derived

0 commit comments

Comments
 (0)