Skip to content

Commit e53ff5b

Browse files
committed
docs(#3241): namespace decorator types
1 parent b63b467 commit e53ff5b

File tree

8 files changed

+27
-16
lines changed

8 files changed

+27
-16
lines changed

lua/nvim-tree/_meta/api_decorator.lua

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@ error("Cannot require a meta file")
44
local nvim_tree = { api = { decorator = {} } }
55

66
---Highlight group range as per nvim-tree.renderer.highlight_*
7-
---@alias nvim_tree.api.decorator.HighlightRange "none" | "icon" | "name" | "all"
7+
---@alias nvim_tree.api.decorator.highlight_range nvim_tree.config.renderer.highlight
88

99
---Icon position as per renderer.icons.*_placement
10-
---@alias nvim_tree.api.decorator.IconPlacement "none" | "before" | "after" | "signcolumn" | "right_align"
10+
---@alias nvim_tree.api.decorator.icon_placement "none"|nvim_tree.config.renderer.icons.placement
1111

1212
---Names of builtin decorators or your decorator classes. Builtins are ordered lowest to highest priority.
13-
---@alias nvim_tree.api.decorator.Name "Git" | "Opened" | "Hidden" | "Modified" | "Bookmarks" | "Diagnostics" | "Copied" | "Cut" | nvim_tree.api.decorator.UserDecorator
13+
---@alias nvim_tree.api.decorator.types nvim_tree.api.decorator.UserDecorator|"Git"|"Opened"|"Hidden"|"Modified"|"Bookmarks"|"Diagnostics"|"Copied"|"Cut"
1414

1515
---A string for rendering, with optional highlight groups to apply to it
16-
---@class (exact) nvim_tree.api.HighlightedString
16+
---@class (exact) nvim_tree.api.decorator.highlighted_string
1717
---@field str string
1818
---@field hl string[]
1919

2020
---Custom decorator, see :help nvim-tree-decorators
2121
---
2222
---@class (exact) nvim_tree.api.decorator.UserDecorator
2323
---@field protected enabled boolean
24-
---@field protected highlight_range nvim_tree.api.decorator.HighlightRange
25-
---@field protected icon_placement nvim_tree.api.decorator.IconPlacement
24+
---@field protected highlight_range nvim_tree.api.decorator.highlight_range
25+
---@field protected icon_placement nvim_tree.api.decorator.icon_placement
2626
nvim_tree.api.decorator.UserDecorator = {}
2727

2828
---Create your decorator class
@@ -37,13 +37,13 @@ function nvim_tree.api.decorator.UserDecorator:new() end
3737
---Abstract: optionally implement to set the node's icon
3838
---
3939
---@param node nvim_tree.api.Node
40-
---@return nvim_tree.api.HighlightedString? icon_node
40+
---@return nvim_tree.api.decorator.highlighted_string? icon_node
4141
function nvim_tree.api.decorator.UserDecorator:icon_node(node) end
4242

4343
---Abstract: optionally implement to provide icons and the highlight groups for your icon_placement.
4444
---
4545
---@param node nvim_tree.api.Node
46-
---@return nvim_tree.api.HighlightedString[]? icons
46+
---@return nvim_tree.api.decorator.highlighted_string[]? icons
4747
function nvim_tree.api.decorator.UserDecorator:icons(node) end
4848

4949
---Abstract: optionally implement to provide one highlight group to apply to your highlight_range.
@@ -55,5 +55,5 @@ function nvim_tree.api.decorator.UserDecorator:highlight_group(node) end
5555
---Define a sign. This should be called in the constructor.
5656
---
5757
---@protected
58-
---@param icon nvim_tree.api.HighlightedString?
58+
---@param icon nvim_tree.api.decorator.highlighted_string?
5959
function nvim_tree.api.decorator.UserDecorator:define_sign(icon) end

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+
---TODO #3241 add an alias for builtins
6465
---(default: `{ "Git", "Open", "Hidden", "Modified", "Bookmark", "Diagnostics", "Copied", "Cut", }`)
6566
---@field decorators? (string|nvim_tree.api.decorator.UserDecorator)[]
6667
---

lua/nvim-tree/api.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,14 @@ local api = {
9696

9797

9898
--
99-
-- Map before-setup implementations, most throw an error notification "nvim-tree setup not called".
99+
-- Map before-setup function implementations, most throw an error notification "nvim-tree setup not called".
100100
--
101101
require("nvim-tree.api.impl.pre")(api)
102102

103103

104+
---#TODO 3241
105+
---Public API classes
106+
-- api.decorator = require("nvim-tree.api.decorator")
107+
104108

105109
return api

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ local function hydrate_post(api)
254254
api.map.keymap.current = keymap.get_keymap
255255
end
256256

257+
---#TODO 3241 hydrate function, for clarity
258+
257259
---Re-hydrate api
258260
---@param api table not properly typed to prevent LSP from referencing implementations
259261
return function(api)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ local function hydrate_pre(api)
6565
api.decorator.UserDecorator = UserDecorator --[[@as nvim_tree.api.decorator.UserDecorator]]
6666
end
6767

68+
---#TODO 3241 hydrate function, for clarity
69+
6870
---Hydrate api
6971
---@param api table not properly typed to prevent LSP from referencing implementations
7072
return function(api)

lua/nvim-tree/renderer/builder.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ local GitDecorator = require("nvim-tree.renderer.decorator.git")
1414
local HiddenDecorator = require("nvim-tree.renderer.decorator.hidden")
1515
local ModifiedDecorator = require("nvim-tree.renderer.decorator.modified")
1616
local OpenDecorator = require("nvim-tree.renderer.decorator.opened")
17-
local UserDecorator = require("nvim-tree.renderer.decorator.user")
17+
local UserDecorator = require("nvim-tree.api").decorator.UserDecorator
1818

1919
local pad = require("nvim-tree.renderer.components.padding")
2020

21-
---@alias HighlightedString nvim_tree.api.HighlightedString
21+
---@alias HighlightedString nvim_tree.api.decorator.highlighted_string
2222

2323
-- Builtin Decorators
24-
---@type table<nvim_tree.api.decorator.Name, Decorator>
24+
---@type table<nvim_tree.api.decorator.types, Decorator>
2525
local BUILTIN_DECORATORS = {
2626
Git = GitDecorator,
2727
Open = OpenDecorator,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ local notify = require("nvim-tree.notify")
33
local Decorator = require("nvim-tree.renderer.decorator")
44
local DirectoryNode = require("nvim-tree.node.directory")
55

6-
---@class (exact) GitHighlightedString: nvim_tree.api.HighlightedString
6+
---@class (exact) GitHighlightedString: nvim_tree.api.decorator.highlighted_string
77
---@field ord number decreasing priority
88

99
---@alias GitStatusStrings "deleted" | "ignored" | "renamed" | "staged" | "unmerged" | "unstaged" | "untracked"

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
local Class = require("nvim-tree.classic")
22

3+
--- #TODO 3241 split this into abstract interface for API and concrete to return to user
4+
35
---Abstract Decorator
46
---@class (exact) Decorator: Class
57
---@field protected enabled boolean
6-
---@field protected highlight_range nvim_tree.api.decorator.HighlightRange
7-
---@field protected icon_placement nvim_tree.api.decorator.IconPlacement
8+
---@field protected highlight_range nvim_tree.api.decorator.highlight_range
9+
---@field protected icon_placement nvim_tree.api.decorator.icon_placement
810
local Decorator = Class:extend()
911

1012
---@class (exact) DecoratorArgs

0 commit comments

Comments
 (0)