Skip to content

Commit b30b270

Browse files
committed
docs(#3241): separate api and class generation configs, namespace classes without their filename, nicer generation placeholder
1 parent e466a37 commit b30b270

12 files changed

Lines changed: 97 additions & 95 deletions

File tree

doc/nvim-tree-lua.txt

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -890,12 +890,12 @@ Require and register it during |nvim-tree-setup|:
890890
<
891891
Contents of `my-decorator.lua`:
892892
>lua
893-
---@class (exact) MyDecorator: nvim_tree.api.decorator.Decorator
893+
---@class (exact) MyDecorator: nvim_tree.api.Decorator
894894
---@field private my_icon1 nvim_tree.api.decorator.highlighted_string
895895
---@field private my_icon2 nvim_tree.api.decorator.highlighted_string
896896
---@field private my_icon_node nvim_tree.api.decorator.highlighted_string
897897
---@field private my_highlight_group string
898-
local MyDecorator = require("nvim-tree.api").decorator.Decorator:extend()
898+
local MyDecorator = require("nvim-tree.api").Decorator:extend()
899899

900900
---Mandatory constructor :new() will be called once per tree render, with no arguments.
901901
function MyDecorator:new()
@@ -1366,7 +1366,7 @@ 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.Decorator)[]`)
1369+
{decorators}? (`(string|nvim_tree.api.Decorator)[]`)
13701370
(default:
13711371
`{ "Git", "Open", "Hidden", "Modified", "Bookmark", "Diagnostics", "Copied", "Cut", }`)
13721372
• {highlight_git}? (`nvim_tree.config.renderer.highlight`)
@@ -2362,6 +2362,9 @@ Following is the default configuration, see |nvim_tree.config| for details. >lua
23622362
},
23632363
}
23642364
<
2365+
2366+
2367+
23652368
==============================================================================
23662369
API *nvim-tree-api*
23672370

@@ -3200,7 +3203,7 @@ winid({opts}) *nvim_tree.api.tree.winid()*
32003203
==============================================================================
32013204
API: Decorator *nvim-tree-api-decorator*
32023205

3203-
*nvim_tree.api.decorator.Decorator*
3206+
*nvim_tree.api.Decorator*
32043207
Extends: |nvim_tree.Class|
32053208

32063209
Abstract Decorator interface
@@ -3209,27 +3212,23 @@ API: Decorator *nvim-tree-api-decorator*
32093212
{enabled} (`boolean`)
32103213
• {highlight_range} (`nvim_tree.api.decorator.highlight_range`)
32113214
• {icon_placement} (`nvim_tree.api.decorator.icon_placement`)
3212-
• {icon_node} (`fun(self: nvim_tree.api.decorator.Decorator, node: nvim_tree.api.Node): nvim_tree.api.decorator.highlighted_string?`)
3213-
See
3214-
|nvim_tree.api.decorator.Decorator:icon_node()|.
3215-
{icons} (`fun(self: nvim_tree.api.decorator.Decorator, node: nvim_tree.api.Node): nvim_tree.api.decorator.highlighted_string[]?`)
3216-
See |nvim_tree.api.decorator.Decorator:icons()|.
3217-
• {highlight_group} (`fun(self: nvim_tree.api.decorator.Decorator, node: nvim_tree.api.Node): string?`)
3218-
See
3219-
|nvim_tree.api.decorator.Decorator:highlight_group()|.
3220-
• {define_sign} (`fun(self: nvim_tree.api.decorator.Decorator, icon: nvim_tree.api.decorator.highlighted_string?)`)
3221-
See
3222-
|nvim_tree.api.decorator.Decorator:define_sign()|.
3223-
3224-
3225-
*nvim_tree.api.decorator.Decorator:define_sign()*
3226-
Decorator:define_sign({icon})
3215+
• {icon_node} (`fun(self: nvim_tree.api.Decorator, node: nvim_tree.api.Node): nvim_tree.api.decorator.highlighted_string?`)
3216+
See |nvim_tree.api.Decorator:icon_node()|.
3217+
{icons} (`fun(self: nvim_tree.api.Decorator, node: nvim_tree.api.Node): nvim_tree.api.decorator.highlighted_string[]?`)
3218+
See |nvim_tree.api.Decorator:icons()|.
3219+
• {highlight_group} (`fun(self: nvim_tree.api.Decorator, node: nvim_tree.api.Node): string?`)
3220+
See |nvim_tree.api.Decorator:highlight_group()|.
3221+
• {define_sign} (`fun(self: nvim_tree.api.Decorator, icon: nvim_tree.api.decorator.highlighted_string?)`)
3222+
See |nvim_tree.api.Decorator:define_sign()|.
3223+
3224+
3225+
Decorator:define_sign({icon}) *nvim_tree.api.Decorator:define_sign()*
32273226
Defines a sign. This should be called in the constructor.
32283227

32293228
Parameters: ~
32303229
{icon} (`nvim_tree.api.decorator.highlighted_string?`)
32313230

3232-
*nvim_tree.api.decorator.Decorator:highlight_group()*
3231+
*nvim_tree.api.Decorator:highlight_group()*
32333232
Decorator:highlight_group({node})
32343233
Abstract: optionally implement to provide one highlight group to apply to
32353234
your highlight_range.
@@ -3240,8 +3239,7 @@ Decorator:highlight_group({node})
32403239
Return: ~
32413240
(`string?`) highlight_group
32423241

3243-
*nvim_tree.api.decorator.Decorator:icon_node()*
3244-
Decorator:icon_node({node})
3242+
Decorator:icon_node({node}) *nvim_tree.api.Decorator:icon_node()*
32453243
Abstract: optionally implement to set the node's icon
32463244

32473245
Parameters: ~
@@ -3250,7 +3248,7 @@ Decorator:icon_node({node})
32503248
Return: ~
32513249
(`nvim_tree.api.decorator.highlighted_string?`) icon_node
32523250

3253-
Decorator:icons({node}) *nvim_tree.api.decorator.Decorator:icons()*
3251+
Decorator:icons({node}) *nvim_tree.api.Decorator:icons()*
32543252
Abstract: optionally implement to provide icons and the highlight groups
32553253
for your icon_placement.
32563254

@@ -3281,7 +3279,7 @@ API: Class *nvim-tree-api-class*
32813279

32823280

32833281
Class:as({class}) *nvim_tree.Class:as()*
3284-
Return object if :is otherwise nil
3282+
Return object if |nvim_tree.Class:is()| otherwise nil
32853283

32863284
Parameters: ~
32873285
{class} (`any`)

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---@meta
2-
local nvim_tree = { api = { decorator = {} } }
2+
local nvim_tree = { api = {} }
33

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

@@ -15,7 +15,7 @@ local Class = require("nvim-tree.classic")
1515
---
1616
---Names of builtin decorators or your decorator classes. Builtins are ordered lowest to highest priority.
1717
---
18-
---@alias nvim_tree.api.decorator.types nvim_tree.api.decorator.Decorator|"Git"|"Opened"|"Hidden"|"Modified"|"Bookmarks"|"Diagnostics"|"Copied"|"Cut"
18+
---@alias nvim_tree.api.decorator.types nvim_tree.api.Decorator|"Git"|"Opened"|"Hidden"|"Modified"|"Bookmarks"|"Diagnostics"|"Copied"|"Cut"
1919

2020
---
2121
---A string for rendering, with optional highlight groups to apply to it
@@ -27,12 +27,12 @@ local Class = require("nvim-tree.classic")
2727
---
2828
---Abstract Decorator interface
2929
---
30-
---@class nvim_tree.api.decorator.Decorator: nvim_tree.Class
30+
---@class nvim_tree.api.Decorator: nvim_tree.Class
3131
---@field enabled boolean
3232
---@field highlight_range nvim_tree.api.decorator.highlight_range
3333
---@field icon_placement nvim_tree.api.decorator.icon_placement
3434
local Decorator = Class:extend()
35-
nvim_tree.api.decorator.Decorator = Decorator
35+
nvim_tree.api.Decorator = Decorator
3636

3737
---
3838
---Abstract: optionally implement to set the node's icon
@@ -61,11 +61,4 @@ function Decorator:highlight_group(node) end
6161
---@param icon nvim_tree.api.decorator.highlighted_string?
6262
function Decorator:define_sign(icon) end
6363

64-
---
65-
---@class nvim_tree.api.decorator.UserDecorator: nvim_tree.api.decorator.Decorator
66-
---@nodoc
67-
---@deprecated use `nvim_tree.api.decorator.Decorator`
68-
---
69-
nvim_tree.api.decorator.UserDecorator = nvim_tree.api.decorator.Decorator
70-
71-
return nvim_tree.api.decorator
64+
return nvim_tree.api.Decorator

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,10 @@ nvim_tree.api.diagnostics = {}
3030
---@deprecated use `nvim_tree.api.health.hi_test()`
3131
function nvim_tree.api.diagnostics.hi_test() end
3232

33+
nvim_tree.api.decorator = {}
34+
35+
---@class nvim_tree.api.decorator.UserDecorator: nvim_tree.api.Decorator
36+
---@deprecated use `nvim_tree.api.Decorator`
37+
nvim_tree.api.decorator.UserDecorator = nvim_tree.api.Decorator
38+
3339
return nvim_tree.api

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,3 @@
88
---default-config-injection-placeholder
99
---}
1010
---```
11-
---
12-
---placeholder for next section [nvim-tree-api]()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ error("Cannot require a meta file")
6262
---@field symlink_destination? boolean
6363
---
6464
---(default: `{ "Git", "Open", "Hidden", "Modified", "Bookmark", "Diagnostics", "Copied", "Cut", }`)
65-
---@field decorators? (string|nvim_tree.api.decorator.Decorator)[]
65+
---@field decorators? (string|nvim_tree.api.Decorator)[]
6666
---
6767
---(default: `"none"`)
6868
---@field highlight_git? nvim_tree.config.renderer.highlight

lua/nvim-tree/api.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676
---@nodoc
7777
local api = {
7878
commands = require("nvim-tree._meta.api.commands"),
79-
decorator = require("nvim-tree._meta.api.decorator"),
8079
events = require("nvim-tree._meta.api.events"),
8180
filter = require("nvim-tree._meta.api.filter"),
8281
fs = require("nvim-tree._meta.api.fs"),
@@ -87,7 +86,10 @@ local api = {
8786
node = require("nvim-tree._meta.api.node"),
8887
tree = require("nvim-tree._meta.api.tree"),
8988

89+
Decorator = require("nvim-tree._meta.api.decorator"),
90+
9091
config = require("nvim-tree._meta.api.deprecated").config, ---@deprecated
92+
decorator = require("nvim-tree._meta.api.deprecated").decorator, ---@deprecated
9193
diagnostics = require("nvim-tree._meta.api.deprecated").diagnostics, ---@deprecated
9294
live_filter = require("nvim-tree._meta.api.deprecated").live_filter, ---@deprecated
9395
}

lua/nvim-tree/api/impl/legacy.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function M.hydrate(api)
2525
api.diagnostics = api.diagnostics or {}
2626
api.diagnostics.hi_test = api.health.hi_test
2727

28-
api.decorator.UserDecorator = api.decorator.Decorator
28+
api.decorator.UserDecorator = api.Decorator
2929
end
3030

3131
return M

lua/nvim-tree/api/impl/pre.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function M.hydrate(api)
5050
api.health.hi_test = function() require("nvim-tree.appearance.hi-test")() end
5151

5252
-- classes
53-
api.decorator.Decorator = UserDecorator:extend()
53+
api.Decorator = UserDecorator:extend()
5454

5555
-- Hydrate any legacy by mapping to concrete set above
5656
require("nvim-tree.api.impl.legacy").hydrate(api)

lua/nvim-tree/classic.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ function Class:is(class)
7272
return false
7373
end
7474

75-
---Return object if :is otherwise nil
75+
---Return object if [nvim_tree.Class:is()] otherwise nil
7676
---@generic T
7777
---@param class T
7878
---@return T|nil
7979
function Class:as(class)
8080
return self:is(class) and self or nil
8181
end
8282

83-
---Constructor to create instance, call :new and return
83+
---Constructor to create instance, call [nvim_tree.Class:new()] and return
8484
function Class:__call(...)
8585
local obj = setmetatable({}, self)
8686
obj:new(...)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
---@field protected enabled boolean
44
---@field protected highlight_range nvim_tree.api.decorator.highlight_range
55
---@field protected icon_placement nvim_tree.api.decorator.icon_placement
6-
local Decorator = require("nvim-tree._meta.api.decorator").Decorator:extend()
6+
local Decorator = require("nvim-tree._meta.api.decorator"):extend()
77

88
---TODO #3241 create an internal decorator class with explorer member and lose the UserDecorator
99
---@class (exact) DecoratorArgs

0 commit comments

Comments
 (0)