Skip to content

Commit 3b60fa7

Browse files
committed
feat(#2948): decorator classes specified by prefix rather than suffix
1 parent 4bf4a85 commit 3b60fa7

File tree

14 files changed

+109
-109
lines changed

14 files changed

+109
-109
lines changed

doc/nvim-tree-lua.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ Whether to show the destination of the symlink.
929929
*nvim-tree.renderer.decorators*
930930
Highlighting and icons for the nodes, in increasing order of precedence.
931931
Uses strings to specify builtin decorators otherwise specify your
932-
`nvim_tree.api.decorator.DecoratorUser` class.
932+
`nvim_tree.api.decorator.UserDecorator` class.
933933
Type: `nvim_tree.api.decorator.Name[]`, Default: >lua
934934
{
935935
"Git",
@@ -2777,7 +2777,7 @@ Decorators may:
27772777
- Set highlight group for the name or icons
27782778
- Override node icon
27792779

2780-
Create your decorator class via `api.decorator.DecoratorUser:extend()` and add it
2780+
Create your decorator class via `api.decorator.UserDecorator:extend()` and add it
27812781
to |nvim-tree.renderer.decorators|
27822782

27832783
e.g. default decorators with an user decorator being overridden only by Cut: >lua
@@ -2798,9 +2798,9 @@ See `api_decorator.lua` for decorator class definition and full documentation.
27982798
Example decorator: >lua
27992799

28002800
---Create your decorator class
2801-
---@class (exact) MyDecorator: nvim_tree.api.decorator.DecoratorUser
2801+
---@class (exact) MyDecorator: nvim_tree.api.decorator.UserDecorator
28022802
---@field private my_icon nvim_tree.api.HighlightedString
2803-
local MyDecorator = require("nvim-tree.api").decorator.DecoratorUser:extend()
2803+
local MyDecorator = require("nvim-tree.api").decorator.UserDecorator:extend()
28042804

28052805
---Mandatory constructor :new() will be called once per tree render, with no arguments.
28062806
function MyDecorator:new()

lua/nvim-tree.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
284284
special_files = { "Cargo.toml", "Makefile", "README.md", "readme.md" },
285285
hidden_display = "none",
286286
symlink_destination = true,
287-
decorators = { "Git", "Opened", "Hidden", "Modified", "Bookmarks", "Diagnostics", "Copied", "Cut", },
287+
decorators = { "Git", "Open", "Hidden", "Modified", "Bookmark", "Diagnostics", "Copied", "Cut", },
288288
highlight_git = "none",
289289
highlight_diagnostics = "none",
290290
highlight_opened_files = "none",

lua/nvim-tree/_meta/api_decorator.lua

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,40 @@ local nvim_tree = {}
1010
---@alias nvim_tree.api.decorator.IconPlacement "none" | "before" | "after" | "signcolumn" | "right_align"
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.DecoratorUser
13+
---@alias nvim_tree.api.decorator.Name "Git" | "Opened" | "Hidden" | "Modified" | "Bookmarks" | "Diagnostics" | "Copied" | "Cut" | nvim_tree.api.decorator.UserDecorator
1414

1515
---Custom decorator, see :help nvim-tree-decorators
1616
---
17-
---@class (exact) nvim_tree.api.decorator.DecoratorUser
17+
---@class (exact) nvim_tree.api.decorator.UserDecorator
1818
---@field protected enabled boolean
1919
---@field protected highlight_range nvim_tree.api.decorator.HighlightRange
2020
---@field protected icon_placement nvim_tree.api.decorator.IconPlacement
2121

2222
---Abstract: no-args constructor must be implemented and will be called once per tree render.
2323
---Must set all fields.
2424
---
25-
function nvim_tree.api.decorator.DecoratorUser:new() end
25+
function nvim_tree.api.decorator.UserDecorator:new() end
2626

2727
---Abstract: optionally implement to set the node's icon
2828
---
2929
---@param node nvim_tree.api.Node
3030
---@return nvim_tree.api.HighlightedString? icon_node
31-
function nvim_tree.api.decorator.DecoratorUser:icon_node(node) end
31+
function nvim_tree.api.decorator.UserDecorator:icon_node(node) end
3232

3333
---Abstract: optionally implement to provide icons and the highlight groups for your icon_placement.
3434
---
3535
---@param node nvim_tree.api.Node
3636
---@return nvim_tree.api.HighlightedString[]? icons
37-
function nvim_tree.api.decorator.DecoratorUser:icons(node) end
37+
function nvim_tree.api.decorator.UserDecorator:icons(node) end
3838

3939
---Abstract: optionally implement to provide one highlight group to apply to your highlight_range.
4040
---
4141
---@param node nvim_tree.api.Node
4242
---@return string? highlight_group
43-
function nvim_tree.api.decorator.DecoratorUser:highlight_group(node) end
43+
function nvim_tree.api.decorator.UserDecorator:highlight_group(node) end
4444

4545
---Define a sign. This should be called in the constructor.
4646
---
4747
---@protected
4848
---@param icon nvim_tree.api.HighlightedString?
49-
function nvim_tree.api.decorator.DecoratorUser:define_sign(icon) end
49+
function nvim_tree.api.decorator.UserDecorator:define_sign(icon) end

lua/nvim-tree/api.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ local notify = require("nvim-tree.notify")
1111
local DirectoryNode = require("nvim-tree.node.directory")
1212
local FileLinkNode = require("nvim-tree.node.file-link")
1313
local RootNode = require("nvim-tree.node.root")
14-
local DecoratorUser = require("nvim-tree.renderer.decorator.user")
14+
local UserDecorator = require("nvim-tree.renderer.decorator.user")
1515

1616
local Api = {
1717
tree = {},
@@ -314,7 +314,7 @@ Api.commands.get = wrap(function()
314314
end)
315315

316316
---Create a decorator class by calling :extend()
317-
---@type nvim_tree.api.decorator.DecoratorUser
318-
Api.decorator.DecoratorUser = DecoratorUser --[[@as nvim_tree.api.decorator.DecoratorUser]]
317+
---@type nvim_tree.api.decorator.UserDecorator
318+
Api.decorator.UserDecorator = UserDecorator --[[@as nvim_tree.api.decorator.UserDecorator]]
319319

320320
return Api

lua/nvim-tree/renderer/builder.lua

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ local Class = require("nvim-tree.classic")
66

77
local DirectoryNode = require("nvim-tree.node.directory")
88

9-
local DecoratorBookmarks = require("nvim-tree.renderer.decorator.bookmarks")
10-
local DecoratorCopied = require("nvim-tree.renderer.decorator.copied")
11-
local DecoratorCut = require("nvim-tree.renderer.decorator.cut")
12-
local DecoratorDiagnostics = require("nvim-tree.renderer.decorator.diagnostics")
13-
local DecoratorGit = require("nvim-tree.renderer.decorator.git")
14-
local DecoratorHidden = require("nvim-tree.renderer.decorator.hidden")
15-
local DecoratorModified = require("nvim-tree.renderer.decorator.modified")
16-
local DecoratorOpened = require("nvim-tree.renderer.decorator.opened")
17-
local DecoratorUser = require("nvim-tree.renderer.decorator.user")
9+
local BookmarkDecorator = require("nvim-tree.renderer.decorator.bookmarks")
10+
local CopiedDecorator = require("nvim-tree.renderer.decorator.copied")
11+
local CutDecorator = require("nvim-tree.renderer.decorator.cut")
12+
local DiagnosticsDecorator = require("nvim-tree.renderer.decorator.diagnostics")
13+
local GitDecorator = require("nvim-tree.renderer.decorator.git")
14+
local HiddenDecorator = require("nvim-tree.renderer.decorator.hidden")
15+
local ModifiedDecorator = require("nvim-tree.renderer.decorator.modified")
16+
local OpenDecorator = require("nvim-tree.renderer.decorator.opened")
17+
local UserDecorator = require("nvim-tree.renderer.decorator.user")
1818

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

@@ -23,14 +23,14 @@ local pad = require("nvim-tree.renderer.components.padding")
2323
-- Builtin Decorators
2424
---@type table<nvim_tree.api.decorator.Name, Decorator>
2525
local BUILTIN_DECORATORS = {
26-
Git = DecoratorGit,
27-
Opened = DecoratorOpened,
28-
Hidden = DecoratorHidden,
29-
Modified = DecoratorModified,
30-
Bookmarks = DecoratorBookmarks,
31-
Diagnostics = DecoratorDiagnostics,
32-
Copied = DecoratorCopied,
33-
Cut = DecoratorCut,
26+
Git = GitDecorator,
27+
Open = OpenDecorator,
28+
Hidden = HiddenDecorator,
29+
Modified = ModifiedDecorator,
30+
Bookmark = BookmarkDecorator,
31+
Diagnostics = DiagnosticsDecorator,
32+
Copied = CopiedDecorator,
33+
Cut = CutDecorator,
3434
}
3535

3636
---@class (exact) AddHighlightArgs
@@ -83,8 +83,8 @@ function Builder:new(args)
8383
---@type Decorator
8484
builtin = BUILTIN_DECORATORS[d]
8585

86-
---@type DecoratorUser
87-
user = d.as and d:as(DecoratorUser)
86+
---@type UserDecorator
87+
user = d.as and d:as(UserDecorator)
8888

8989
if builtin then
9090
table.insert(self.decorators, builtin({ explorer = self.explorer }))
@@ -164,18 +164,18 @@ function Builder:format_line(indent_markers, arrows, icon, name, node)
164164
add_to_end(line, { icon })
165165

166166
for _, d in ipairs(self.decorators) do
167-
add_to_end(line, d:icons_before(not d:is(DecoratorUser) and node or api_node))
167+
add_to_end(line, d:icons_before(not d:is(UserDecorator) and node or api_node))
168168
end
169169

170170
add_to_end(line, { name })
171171

172172
for _, d in ipairs(self.decorators) do
173-
add_to_end(line, d:icons_after(not d:is(DecoratorUser) and node or api_node))
173+
add_to_end(line, d:icons_after(not d:is(UserDecorator) and node or api_node))
174174
end
175175

176176
local rights = {}
177177
for _, d in ipairs(self.decorators) do
178-
add_to_end(rights, d:icons_right_align(not d:is(DecoratorUser) and node or api_node))
178+
add_to_end(rights, d:icons_right_align(not d:is(UserDecorator) and node or api_node))
179179
end
180180
if #rights > 0 then
181181
self.extmarks[self.index] = rights
@@ -194,7 +194,7 @@ function Builder:build_signs(node)
194194
local d, sign_name
195195
for i = #self.decorators, 1, -1 do
196196
d = self.decorators[i]
197-
sign_name = d:sign_name(not d:is(DecoratorUser) and node or api_node)
197+
sign_name = d:sign_name(not d:is(UserDecorator) and node or api_node)
198198
if sign_name then
199199
self.signs[self.index] = sign_name
200200
break
@@ -251,9 +251,9 @@ function Builder:icon_name_decorated(node)
251251
local hl_icon, hl_name
252252
for _, d in ipairs(self.decorators) do
253253
-- maybe overridde icon
254-
icon = d:icon_node((not d:is(DecoratorUser) and node or api_node)) or icon
254+
icon = d:icon_node((not d:is(UserDecorator) and node or api_node)) or icon
255255

256-
hl_icon, hl_name = d:highlight_group_icon_name((not d:is(DecoratorUser) and node or api_node))
256+
hl_icon, hl_name = d:highlight_group_icon_name((not d:is(UserDecorator) and node or api_node))
257257

258258
table.insert(icon_groups, hl_icon)
259259
table.insert(name_groups, hl_name)

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
local Decorator = require("nvim-tree.renderer.decorator")
22

3-
---@class (exact) DecoratorBookmarks: Decorator
3+
---@class (exact) BookmarkDecorator: Decorator
44
---@field private explorer Explorer
55
---@field private icon HighlightedString?
6-
local DecoratorBookmarks = Decorator:extend()
6+
local BookmarkDecorator = Decorator:extend()
77

8-
---@class DecoratorBookmarks
9-
---@overload fun(args: DecoratorArgs): DecoratorBookmarks
8+
---@class BookmarkDecorator
9+
---@overload fun(args: DecoratorArgs): BookmarkDecorator
1010

1111
---@protected
1212
---@param args DecoratorArgs
13-
function DecoratorBookmarks:new(args)
13+
function BookmarkDecorator:new(args)
1414
self.explorer = args.explorer
1515

1616
self.enabled = true
@@ -29,7 +29,7 @@ end
2929
---Bookmark icon: renderer.icons.show.bookmarks and node is marked
3030
---@param node Node
3131
---@return HighlightedString[]? icons
32-
function DecoratorBookmarks:icons(node)
32+
function BookmarkDecorator:icons(node)
3333
if self.explorer.marks:get(node) then
3434
return { self.icon }
3535
end
@@ -38,10 +38,10 @@ end
3838
---Bookmark highlight: renderer.highlight_bookmarks and node is marked
3939
---@param node Node
4040
---@return string? highlight_group
41-
function DecoratorBookmarks:highlight_group(node)
41+
function BookmarkDecorator:highlight_group(node)
4242
if self.highlight_range ~= "none" and self.explorer.marks:get(node) then
4343
return "NvimTreeBookmarkHL"
4444
end
4545
end
4646

47-
return DecoratorBookmarks
47+
return BookmarkDecorator
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
local Decorator = require("nvim-tree.renderer.decorator")
22

3-
---@class (exact) DecoratorCopied: Decorator
3+
---@class (exact) CopiedDecorator: Decorator
44
---@field private explorer Explorer
5-
local DecoratorCopied = Decorator:extend()
5+
local CopiedDecorator = Decorator:extend()
66

7-
---@class DecoratorCopied
8-
---@overload fun(args: DecoratorArgs): DecoratorCopied
7+
---@class CopiedDecorator
8+
---@overload fun(args: DecoratorArgs): CopiedDecorator
99

1010
---@protected
1111
---@param args DecoratorArgs
12-
function DecoratorCopied:new(args)
12+
function CopiedDecorator:new(args)
1313
self.explorer = args.explorer
1414

1515
self.enabled = true
@@ -20,10 +20,10 @@ end
2020
---Copied highlight: renderer.highlight_clipboard and node is copied
2121
---@param node Node
2222
---@return string? highlight_group
23-
function DecoratorCopied:highlight_group(node)
23+
function CopiedDecorator:highlight_group(node)
2424
if self.highlight_range ~= "none" and self.explorer.clipboard:is_copied(node) then
2525
return "NvimTreeCopiedHL"
2626
end
2727
end
2828

29-
return DecoratorCopied
29+
return CopiedDecorator
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
local Decorator = require("nvim-tree.renderer.decorator")
22

3-
---@class (exact) DecoratorCut: Decorator
3+
---@class (exact) CutDecorator: Decorator
44
---@field private explorer Explorer
5-
local DecoratorCut = Decorator:extend()
5+
local CutDecorator = Decorator:extend()
66

7-
---@class DecoratorCut
8-
---@overload fun(args: DecoratorArgs): DecoratorCut
7+
---@class CutDecorator
8+
---@overload fun(args: DecoratorArgs): CutDecorator
99

1010
---@protected
1111
---@param args DecoratorArgs
12-
function DecoratorCut:new(args)
12+
function CutDecorator:new(args)
1313
self.explorer = args.explorer
1414

1515
self.enabled = true
@@ -20,10 +20,10 @@ end
2020
---Cut highlight: renderer.highlight_clipboard and node is cut
2121
---@param node Node
2222
---@return string? highlight_group
23-
function DecoratorCut:highlight_group(node)
23+
function CutDecorator:highlight_group(node)
2424
if self.highlight_range ~= "none" and self.explorer.clipboard:is_cut(node) then
2525
return "NvimTreeCutHL"
2626
end
2727
end
2828

29-
return DecoratorCut
29+
return CutDecorator

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ local ICON_KEYS = {
3030
["hint"] = vim.diagnostic.severity.HINT,
3131
}
3232

33-
---@class (exact) DecoratorDiagnostics: Decorator
33+
---@class (exact) DiagnosticsDecorator: Decorator
3434
---@field private explorer Explorer
3535
---@field private diag_icons HighlightedString[]?
36-
local DecoratorDiagnostics = Decorator:extend()
36+
local DiagnosticsDecorator = Decorator:extend()
3737

38-
---@class DecoratorDiagnostics
39-
---@overload fun(args: DecoratorArgs): DecoratorDiagnostics
38+
---@class DiagnosticsDecorator
39+
---@overload fun(args: DecoratorArgs): DiagnosticsDecorator
4040

4141
---@protected
4242
---@param args DecoratorArgs
43-
function DecoratorDiagnostics:new(args)
43+
function DiagnosticsDecorator:new(args)
4444
self.explorer = args.explorer
4545

4646
self.enabled = true
@@ -62,7 +62,7 @@ end
6262
---Diagnostic icon: diagnostics.enable, renderer.icons.show.diagnostics and node has status
6363
---@param node Node
6464
---@return HighlightedString[]? icons
65-
function DecoratorDiagnostics:icons(node)
65+
function DiagnosticsDecorator:icons(node)
6666
if node and self.diag_icons then
6767
local diag_status = diagnostics.get_diag_status(node)
6868
local diag_value = diag_status and diag_status.value
@@ -76,7 +76,7 @@ end
7676
---Diagnostic highlight: diagnostics.enable, renderer.highlight_diagnostics and node has status
7777
---@param node Node
7878
---@return string? highlight_group
79-
function DecoratorDiagnostics:highlight_group(node)
79+
function DiagnosticsDecorator:highlight_group(node)
8080
if self.highlight_range == "none" then
8181
return nil
8282
end
@@ -102,4 +102,4 @@ function DecoratorDiagnostics:highlight_group(node)
102102
end
103103
end
104104

105-
return DecoratorDiagnostics
105+
return DiagnosticsDecorator

0 commit comments

Comments
 (0)