Skip to content

Commit 118057e

Browse files
authored
docs(#3241): add api.Decorator and Class meta with generated help, harden decorator rendering, api.decorator.UserDecorator changed to nvim_tree.api.Decorator in a non-breaking manner (#3259)
* doc(#2934): POC to use gen_vimdoc.lua for decorator meta * doc(#2934): use injected gen_vimdoc.lua from nvim source, move decorators to main help * doc(#2934): tidy and harden scripts * doc(#2934): add nvim_tree.Config meta classes, add nvim_tree.api. meta classes * doc(#2934): add nvim_tree.Config to help * doc(#2934): add nvim_tree.api classes to help * doc(#2934): tidy and correct nvim_tree.Config.UI and nvim_tree.Config.Actions * doc(#2934): tidy and correct nvim_tree.Config.HijackDirectories, format and order nvim_tree.Config * doc(#2934): tidy and nvim_tree.Config top level * doc(#2934): tidy and format nvim_tree.Config.LiveFilter, Modified, Tab, Trash * doc(#2934): tidy and format nvim_tree.Config.FilesystemWatchers, Log * doc(#2934): split nvim_tree.Config into files, Sort and HijackDirectories populate others placeholder * doc(#2934): more generic gen_vimdoc_config module config * doc(#2934): tidy Config.HijackDirectories and Actions, move them into place * doc(#2934): tidy Config.Modified, move into place * doc(#2934): tidy Config.LiveFilter, move into place * doc(#2934): tidy Config.FilesystemWatchers, move into place * doc(#2934): tidy Config.Trash, move into place * doc(#2934): tidy Config.Tab, move into place * doc(#2934): tidy Config.UI, move into place * doc(#2934): tidy Config.Log, move into place * doc(#2934): tidy Config.Notify, move into place * doc(#2934): tidy Config.SystemOpen, move into place * doc(#2934): tidy Config.Help, move into place * doc(#2934): tidy Config.Help, move into place * doc(#2934): tidy Config.Help, move into place * doc(#2934): tidy Config.Diagnostics, move into place * doc(#2934): remove api/decorator as they are out of scope, revert api_decorator.lua changes, retain api opts classes but make them exact * doc(#2934): tidy Config.Filters, move into place * doc(#2934): tidy Config.FilesystemWatchers, move into place * doc(#2934): tidy Config.FilesystemWatchers, Git, move into place * doc(#2934): tidy Config.UpdateFocusedFile, move into place * doc(#2934): tidy Config.Sort, move into place * doc(#2934): tidy Config.View, move into place * doc(#2934): tidy Config.View, move into place * docs(#2934): type DEFAULT_OPTS, use bracketed references to keep luals happy * docs(#2934): tidy, inline some classes * docs(#2934): tidy Config.Renderer * docs(#2934): remove problematic glyphs, tidy other glyphs * docs(#2934): tidy Config.Renderer, ensure functions are parenthesised when necessary * docs(#2934): tidy Config.Renderer * docs(#2934): tidy Config.Renderer, move into place * docs(#2934): tidy Config.Renderer * docs(#2934): tidy Config.FilesystemWatchers * docs(#2934): fix broken links * docs(#2934): fix broken links * docs(#2934): fix broken links * docs(#2934): fix broken links * docs(#2934): refer to nvim in help, not neovim, as this trips the lintdoc spell checker * docs(#2934): fix broken links * docs(#2934): add lintdoc.sh, fix some branding spelling * docs(#2934): update old config links * docs(#2934): remove 5. Opts, 8.2 Highlight: Overhaul, 15.1 Index: Opts, update links as needed * docs(#2934): remove indices * docs(#2934): add bookmarks, put long descriptions into @brief * docs(#2934): move hidden display to verbatim new section * docs(#2934): add config lsp examples, link setup * docs(#2934): normalise heading formatting, remove TOC * docs(#2934): move all icon and highlight info into a table * docs(#2934): move all icon and highlight info into a new section * docs(#2934): normalise all icon and highlight * docs(#2934): extract nvim_tree.Config field descriptions to class overview * docs(#2934): consistent string formatting * docs(#2934): normalise all icon and highlight * docs(#2934): remove @Briefs as they are shown above the class tag * docs(#2934): don't <pre> filters * docs(#2934): add experimental example * docs(#2934): add gen_vimdoc.sh to CI * docs(#2934): add gen_vimdoc.sh to CI * docs(#2934): add gen_vimdoc.sh to CI * docs(#2934): temporarily --ignore-blank-lines during help check * docs(#2934): add lintdoc.sh to CI * docs(#2934): add lintdoc.sh to CI * docs(#2934): add lintdoc.sh to CI * docs(#2934): move Nvim build and help-check to the end for faster turnaround * docs(#2934): use make lintdoc target directly * docs(#2934): CONTRIBUTING.md updates for help generation and lint * docs(#2934): revert API opts classes changes * docs(#2934): harden gen and lint scripts, moving things out of nvim-tree source to prevent luals upset * docs(#2934): harden gen and lint scripts, moving things out of nvim-tree source to prevent luals upset * docs(#2934): fix lintdoc make target * docs(#3088): extract api/tree.lua * docs(#3088): extract api/tree.lua * docs(#2934): move help diff check after lint * docs(#3088): update api.tree references, remove old doc * docs(#3088): extract api/config/mappings.lua * docs(#3088): api.config.mappings -> api.map * docs(#3088): extract api/filter.lua * docs(#3088): move api.git into api.tree * docs(#3088): extract api/health.lua, tidy formatting * docs(#3088): extract api/health.lua, tidy formatting * docs(#3088): remove command descriptions, show lua, link to api * docs(#3088): extract api/marks.lua * docs(#3088): remove completed legacy api.lua members * docs(#3088): extract api/events.lua * docs(#3088): extract api/events.lua * docs(#3088): extract api/fs.lua * docs(#3088): extract api/commands.lua * docs(#3088): extract api/node.lua functions, doc TODO * docs(#3088): move all nvim-tree-api to generated doc * docs(#3088): old api is now impl, use new api * docs(#3088): extract api/node.lua functions, doc WIP * docs(#3088): extract api/node.lua functions, doc WIP * docs(#3088): extract api/node.lua functions, doc WIP * docs(#3088): extract api/node.lua functions * docs(#3088): move api into _meta * docs(#3088): move api-impl out of meta, restore it to its original state with a hyrdrate function * docs(#3088): remove old Api classes, rename impl Api -> api * docs(#3088): tidy migrated annotations * docs(#3088): format nvim_tree.api.commands * docs(#3088): separate api classes at the end * docs(#3088): polish vimdoc config * docs(#3088): format * docs(#2934): polish vimdoc config * docs(#2934): snake case config class names * docs(#2934): snake case config alias names * docs(#2934): note help tag prefixes * docs(#2934): snake case config sections * docs(#2934): move default config to end * docs(#2934): move setup doc from config to quickstart and setup * docs(#2934): index contributing * docs(#3088): cleanup following merge * docs(#3088): tidy section names * docs(#3088): split node.navigate and open, move all filters into api.filter * docs(#3088): hidden->custom toggle default desc * docs(#3088): add legacy filter api mappings * docs(#3088): tidy api meta * docs(#3088): always exclude meta from luacheck, it doesn't offer anything useful * docs(#3088): extract fs.copy, fix api node param optionality, move legacy api to legacy.lua * docs(#3088): correct optionality of nvim_tree.config.view.width fields * docs(#3088): hydrate API before setup with error functions, with some hydrated with their concrete function, wrap removal TODO * docs(#3088): remove api impl error wrap * docs(#3088): split api pre and post, add more comments * docs(#3088): split api pre and post, add more comments * docs(#3088): extract post impl functions, lazy some requires * docs(#3088): lazy api impl requires * Revert "docs(#3088): lazy api impl requires" This reverts commit c6ea6c5. * docs(#3088): minimise api pre following tests * docs(#3088): move node classes under api with logical order * docs(#3088): document node and git classes, namespace internal and external git classes, redact node subclasses * docs(#3088): fix merge issue * docs(#3088): tidy pre comments * docs(#3088): collapse node and fs submodules * docs(#3088): move api help and classes back into api.lua * docs(#3088): resize command calls api, not view * docs(#3088): tidy api map names * docs(#3088): revert api.git refactor, provide deprecated api meta * docs(#3088): add deprecated api @see * docs(#3088): class fixes following merge, disable luacheck on scripts * docs(#3088): Node:should_expand nops * docs(#3088): fix _git return * docs(#3088): add meta for legacy api * docs(#3088): mark deprecated api modules, use proper namespacing for deprecateds * docs(#3088): gen_vimdoc now uses full paths, requires a patch for a FIXME * docs(#3088): add vim_gendoc patches * Revert "docs(#3088): add vim_gendoc patches" This reverts commit ebb9909. * Revert "docs(#3088): gen_vimdoc now uses full paths, requires a patch for a FIXME" This reverts commit ff0184a. * docs(#3088): split gen_vimdoc_config into chunks to avoid filename clashes, as gen_vimdoc keys sections by filename * docs(#3088): move legacy api into api.impl.legacy, fixes following testing * docs(#3088): remove merge leftover * docs(#3088): tidy contrib * docs(#3088): clarify backwards compatibility * docs(#3088): clarify help generation in contributing * docs(#3088): contributing index * docs(#3088): help-update.sh -> help-defaults.sh now using a /tmp file to prevent runaway FS updates * docs(#3088): help-update.sh -> help-defaults.sh now using a /tmp file to prevent runaway FS updates * docs(#3088): CI runs make lintdoc to avoid muddying help-check with unnecessary build and possible Nvim lint failures * docs(#3088): unify help and readme, clarify some wording * docs(#3088): test a readme toc * docs(#3088): test a readme toc * docs(#3088): unify help generation and lint into vimdoc.sh, generation uses nvim source build to execute (#3260) * docs(#3241): unify help generation and lint into vimdoc.sh, generation uses nvim source build to execute * docs(#3241): unify help generation and lint into vimdoc.sh, generation uses nvim source build to execute * docs(#3241): unify help generation and lint into vimdoc.sh, generation uses nvim source build to execute * docs(#3241): unify help generation and lint into vimdoc.sh, generation uses nvim source build to execute * docs(#3241): namespace decorator types * docs(#3241): namespace decorator types * docs(#3241): namespace decorator types * docs(#3241): api exposes nvim_tree.api.decorator.Decorator interface, UserDecorator deprecated * docs(#3241): move decorator meta into place * docs(#3241): generate decorator help * docs(#3241): separate api and class generation configs, namespace classes without their filename, nicer generation placeholder * docs(#3241): fix potential bug in builder: passing a nil node to a user decorator * docs(#3241): nvim-tree-api-decorator brief * docs(#3241): Decorator class documentation * docs(#3241): add placholder to vimdoc.sh * docs(#3241): extract nvim_tree.config.renderer.decorator, add decorators to hl help section * docs(#3241): use general nvim_tree.api.highlighted_string * docs(#3241): add nvim-tree-class-decorator-example * docs(#3241): move renderer alias doc to the class * docs(#3241): Class -> nvim_tree.Class * docs(#3241): Class -> nvim_tree.Class * docs(#3241): document nvim_tree.Class * docs(#3241): fix help lua indentation * docs(#3241): extract builtin decorator interface, partially complete * docs(#3241): extracted BuiltinDecorator * docs(#3241): add BuiltinDecorator constructor * docs(#3241): revert api function changes * docs(#3241): revert api function changes * docs(#3241): vimdoc polish * docs(#3241): tidy * docs(#3241): tidy
1 parent c0b18e4 commit 118057e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1243
-631
lines changed

doc/nvim-tree-lua.txt

Lines changed: 460 additions & 178 deletions
Large diffs are not rendered by default.

lua/nvim-tree.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ function M.setup(conf)
813813
vim.g.NvimTreeSetup = 1
814814
vim.api.nvim_exec_autocmds("User", { pattern = "NvimTreeSetup" })
815815

816-
require("nvim-tree.api.impl.post")(api)
816+
require("nvim-tree.api.impl.post").hydrate(api)
817817
end
818818

819819
vim.g.NvimTreeRequired = 1
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---@meta
2+
3+
---@brief
4+
---Highlighting and icons for nodes are provided by Decorators, see [nvim-tree-icons-highlighting] for an overview.
5+
---
6+
---Decorators are rendered in [nvim_tree.config.renderer] {decorators} order of additive precedence, with later decorators applying additively over earlier.
7+
---
8+
---You may provide your own in addition to the builtin decorators, see |nvim-tree-class-decorator-example|.
9+
---
10+
---Decorators may:
11+
---- Add icons
12+
---- Set a highlight group name for the name or icons
13+
---- Override node icon
14+
---
15+
---To register your decorator:
16+
---- Create a class that extends [nvim_tree.api.Decorator]
17+
---- Register it by adding the class to [nvim_tree.config.renderer] {decorators}
18+
---
19+
---Your decorator will be constructed and executed each time the tree is rendered.
20+
---
21+
---Your class must:
22+
---- [nvim_tree.Class:extend()] the interface [nvim_tree.api.Decorator]
23+
---- Provide a no-arguments constructor [nvim_tree.Class:new()] that sets the mandatory fields:
24+
--- - {enabled}
25+
--- - {highlight_range}
26+
--- - {icon_placement}
27+
---- Call [nvim_tree.api.Decorator:define_sign()] in your constructor when {icon_placement} is `"signcolumn"`
28+
---
29+
---Your class may:
30+
---- Implement methods to provide decorations:
31+
--- - [nvim_tree.api.Decorator:highlight_group()]
32+
--- - [nvim_tree.api.Decorator:icon_node()]
33+
--- - [nvim_tree.api.Decorator:icons()]
34+
35+
local nvim_tree = { api = {} }
36+
37+
local Class = require("nvim-tree.classic")
38+
39+
---
40+
---Text or glyphs with optional highlight group names to apply to it.
41+
---
42+
---@class nvim_tree.api.highlighted_string
43+
---
44+
---One or many glyphs/characters.
45+
---@field str string
46+
---
47+
---Highlight group names to apply in order. Empty table for no highlighting.
48+
---@field hl string[]
49+
50+
51+
---
52+
---Decorator interface
53+
---
54+
---@class nvim_tree.api.Decorator: nvim_tree.Class
55+
---
56+
---Enable this decorator.
57+
---@field enabled boolean
58+
---
59+
---What to highlight: [nvim_tree.config.renderer.highlight]
60+
---@field highlight_range nvim_tree.config.renderer.highlight
61+
---
62+
---Where to place the icons: [nvim_tree.config.renderer.icons.placement]
63+
---@field icon_placement "none"|nvim_tree.config.renderer.icons.placement
64+
---
65+
local Decorator = Class:extend()
66+
nvim_tree.api.Decorator = Decorator
67+
68+
---
69+
---Icon to override for the node.
70+
---
71+
---Abstract, optional to implement.
72+
---
73+
---@param node nvim_tree.api.Node
74+
---@return nvim_tree.api.highlighted_string? icon `nil` for no override
75+
function Decorator:icon_node(node) end
76+
77+
---
78+
---Icons to add to the node as per {icon_placement}
79+
---
80+
---Abstract, optional to implement.
81+
---
82+
---@param node nvim_tree.api.Node
83+
---@return nvim_tree.api.highlighted_string[]? icons `nil` or empty table for no icons. Only the first glyph of {str} is used when {icon_placement} is `"signcolumn"`
84+
function Decorator:icons(node) end
85+
86+
---
87+
---One highlight group that applies additively to the {node} name for {highlight_range}.
88+
---
89+
---Abstract, optional to implement.
90+
---
91+
---@param node nvim_tree.api.Node
92+
---@return string? highlight group name `nil` when no highlighting to apply to the node
93+
function Decorator:highlight_group(node) end
94+
95+
---
96+
---Defines a sign for an icon. This is mandatory and necessary only when {icon_placement} is `"signcolumn"`
97+
---
98+
---This must be called during your constructor for all icons that you will return from [nvim_tree.api.Decorator:icons()]
99+
---
100+
---@param icon nvim_tree.api.highlighted_string? does nothing if nil
101+
function Decorator:define_sign(icon) end
102+
103+
return nvim_tree.api.Decorator
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---@meta
2+
error("Cannot require a meta file")
3+
4+
---@brief
5+
---
6+
---A decorator class for nodes named "example", overriding all builtin decorators except for Cut.
7+
---- Highlights node name with `IncSearch`
8+
---- Creates two icons `"1"` and `"2"` placed after the node name, highlighted with `DiffAdd` and `DiffText`
9+
---- Replaces the node icon with `"N"`, highlighted with `Error `
10+
---
11+
---Create a class file `~/.config/nvim/lua/my-decorator.lua`
12+
---
13+
---Require and register it during |nvim-tree-setup|:
14+
---```lua
15+
---
16+
--- local MyDecorator = require("my-decorator")
17+
---
18+
--- require("nvim-tree").setup({
19+
--- renderer = {
20+
--- decorators = {
21+
--- "Git",
22+
--- "Open",
23+
--- "Hidden",
24+
--- "Modified",
25+
--- "Bookmark",
26+
--- "Diagnostics",
27+
--- "Copied",
28+
--- MyDecorator,
29+
--- "Cut",
30+
--- },
31+
--- },
32+
--- })
33+
---```
34+
---Contents of `my-decorator.lua`:
35+
---```lua
36+
---
37+
--- ---@class (exact) MyDecorator: nvim_tree.api.Decorator
38+
--- ---@field private my_icon1 nvim_tree.api.highlighted_string
39+
--- ---@field private my_icon2 nvim_tree.api.highlighted_string
40+
--- ---@field private my_icon_node nvim_tree.api.highlighted_string
41+
--- ---@field private my_highlight_group string
42+
--- local MyDecorator = require("nvim-tree.api").Decorator:extend()
43+
---
44+
--- ---Mandatory constructor :new() will be called once per tree render, with no arguments.
45+
--- function MyDecorator:new()
46+
--- self.enabled = true
47+
--- self.highlight_range = "name"
48+
--- self.icon_placement = "after"
49+
---
50+
--- -- create your icons and highlights once, applied to every node
51+
--- self.my_icon1 = { str = "1", hl = { "DiffAdd" } }
52+
--- self.my_icon2 = { str = "2", hl = { "DiffText" } }
53+
--- self.my_icon_node = { str = "N", hl = { "Error" } }
54+
--- self.my_highlight_group = "IncSearch"
55+
---
56+
--- -- Define the icon signs only once
57+
--- -- Only needed if you are using icon_placement = "signcolumn"
58+
--- -- self:define_sign(self.my_icon1)
59+
--- -- self:define_sign(self.my_icon2)
60+
--- end
61+
---
62+
--- ---Override node icon
63+
--- ---@param node nvim_tree.api.Node
64+
--- ---@return nvim_tree.api.highlighted_string? icon_node
65+
--- function MyDecorator:icon_node(node)
66+
--- if node.name == "example" then
67+
--- return self.my_icon_node
68+
--- else
69+
--- return nil
70+
--- end
71+
--- end
72+
---
73+
--- ---Return two icons for DecoratorIconPlacement "after"
74+
--- ---@param node nvim_tree.api.Node
75+
--- ---@return nvim_tree.api.highlighted_string[]? icons
76+
--- function MyDecorator:icons(node)
77+
--- if node.name == "example" then
78+
--- return { self.my_icon1, self.my_icon2, }
79+
--- else
80+
--- return nil
81+
--- end
82+
--- end
83+
---
84+
--- ---Exactly one highlight group for DecoratorHighlightRange "name"
85+
--- ---@param node nvim_tree.api.Node
86+
--- ---@return string? highlight_group
87+
--- function MyDecorator:highlight_group(node)
88+
--- if node.name == "example" then
89+
--- return self.my_highlight_group
90+
--- else
91+
--- return nil
92+
--- end
93+
--- end
94+
---
95+
--- return MyDecorator
96+
---```

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/api_decorator.lua

Lines changed: 0 additions & 59 deletions
This file was deleted.

lua/nvim-tree/_meta/classes.lua

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
---@meta
22
error("Cannot require a meta file")
33

4-
5-
-- TODO #2688
6-
-- These node subclasses are not ready for public exposure as they are:
7-
-- - not classic classes
8-
-- - only used in a few locations: api.tree.get_nodes and UserDecorator
9-
104
---
115
---File
126
---

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ error("Cannot require a meta file")
6060
---
6161
---{open_win_config} is passed to [nvim_open_win()], default:
6262
---```lua
63-
---{
64-
--- col = 1,
65-
--- row = 1,
66-
--- relative = "cursor",
67-
--- border = "shadow",
68-
--- style = "minimal",
69-
---}
63+
--- {
64+
--- col = 1,
65+
--- row = 1,
66+
--- relative = "cursor",
67+
--- border = "shadow",
68+
--- style = "minimal",
69+
--- }
7070
---```
7171
---You shouldn't define {width} and {height} values here. They will be overridden to fit the file_popup content.
7272
---@class nvim_tree.config.actions.file_popup

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
---
44
---```lua
55
---
6-
------@type nvim_tree.config
7-
---local config = {
8-
---default-config-injection-placeholder
9-
---}
6+
--- ---@type nvim_tree.config
7+
--- local config = {
8+
--- default-config-injection-placeholder
9+
--- }
1010
---```
11-
---

0 commit comments

Comments
 (0)