@@ -5,18 +5,19 @@ local notify = require "nvim-tree.notify"
5
5
local git = require " nvim-tree.renderer.components.git"
6
6
local pad = require " nvim-tree.renderer.components.padding"
7
7
local icons = require " nvim-tree.renderer.components.icons"
8
- local modified = require " nvim-tree.renderer.components.modified"
9
8
local diagnostics = require " nvim-tree.renderer.components.diagnostics"
10
- local bookmarks = require " nvim-tree.renderer.components.bookmarks"
11
9
12
10
local HL_POSITION = require (" nvim-tree.enum" ).HL_POSITION
11
+ local ICON_PLACEMENT = require (" nvim-tree.enum" ).ICON_PLACEMENT
13
12
13
+ --- @class Builder
14
+ --- @field decorators Decorator[]
14
15
local Builder = {}
15
16
Builder .__index = Builder
16
17
17
18
local DEFAULT_ROOT_FOLDER_LABEL = " :~:s?$?/..?"
18
19
19
- function Builder .new (root_cwd )
20
+ function Builder .new (root_cwd , decorators )
20
21
return setmetatable ({
21
22
index = 0 ,
22
23
depth = 0 ,
@@ -25,6 +26,7 @@ function Builder.new(root_cwd)
25
26
markers = {},
26
27
signs = {},
27
28
root_cwd = root_cwd ,
29
+ decorators = decorators ,
28
30
}, Builder )
29
31
end
30
32
@@ -80,22 +82,6 @@ function Builder:configure_diagnostics_icon_placement(where)
80
82
return self
81
83
end
82
84
83
- function Builder :configure_bookmark_icon_placement (where )
84
- if where ~= " after" and where ~= " before" and where ~= " signcolumn" then
85
- where = " before" -- default before
86
- end
87
- self .bookmarks_placement = where
88
- return self
89
- end
90
-
91
- function Builder :configure_modified_placement (where )
92
- if where ~= " after" and where ~= " before" and where ~= " signcolumn" then
93
- where = " after" -- default after
94
- end
95
- self .modified_placement = where
96
- return self
97
- end
98
-
99
85
function Builder :configure_symlink_destination (show )
100
86
self .symlink_destination = show
101
87
return self
265
251
--- @param node table
266
252
--- @return HighlightedString | nil icon
267
253
function Builder :_get_modified_icon (node )
268
- local modified_icon = modified . get_icon (node )
269
- if modified_icon and self .modified_placement == " signcolumn" then
254
+ local modified_icon = self . decorators . modified : get_icon (node )
255
+ if modified_icon and self .decorators . modified . icon_placement == ICON_PLACEMENT . signcolumn then
270
256
table.insert (self .signs , {
271
257
sign = modified_icon .hl [1 ],
272
258
lnum = self .index + 1 ,
280
266
--- @param node table
281
267
--- @return HighlightedString[] | nil icon
282
268
function Builder :_get_bookmark_icon (node )
283
- local bookmark_icon = bookmarks . get_icon (node )
284
- if bookmark_icon and self .bookmarks_placement == " signcolumn" then
269
+ local bookmark_icon = self . decorators . bookmark : get_icon (node )
270
+ if bookmark_icon and self .decorators . bookmark . icon_placement == ICON_PLACEMENT . signcolumn then
285
271
table.insert (self .signs , {
286
272
sign = bookmark_icon .hl [1 ],
287
273
lnum = self .index + 1 ,
@@ -327,6 +313,23 @@ function Builder:_append_highlight(node, get_hl, icon_hl, name_hl)
327
313
end
328
314
end
329
315
316
+ --- Append optional highlighting to icon or name.
317
+ --- @param node table
318
+ --- @param decorator Decorator
319
+ --- @param icon_hl string[] icons to append to
320
+ --- @param name_hl string[] names to append to
321
+ function Builder :_append_dec_highlight (node , decorator , icon_hl , name_hl )
322
+ local pos , hl = decorator :get_highlight (node )
323
+ if pos ~= HL_POSITION .none and hl then
324
+ if pos == HL_POSITION .all or pos == HL_POSITION .icon then
325
+ table.insert (icon_hl , hl )
326
+ end
327
+ if pos == HL_POSITION .all or pos == HL_POSITION .name then
328
+ table.insert (name_hl , hl )
329
+ end
330
+ end
331
+ end
332
+
330
333
--- @param indent_markers HighlightedString[]
331
334
--- @param arrows HighlightedString[] | nil
332
335
--- @param icon HighlightedString
@@ -359,13 +362,13 @@ function Builder:_format_line(indent_markers, arrows, icon, name, git_icons, dia
359
362
if git_icons and self .git_placement == " before" then
360
363
add_to_end (line , git_icons )
361
364
end
362
- if modified_icon and self .modified_placement == " before" then
365
+ if modified_icon and self .decorators . modified . icon_placement == ICON_PLACEMENT . before then
363
366
add_to_end (line , { modified_icon })
364
367
end
365
368
if diagnostics_icon and self .diagnostics_placement == " before" then
366
369
add_to_end (line , { diagnostics_icon })
367
370
end
368
- if bookmark_icon and self .bookmarks_placement == " before" then
371
+ if bookmark_icon and self .decorators . bookmark . icon_placement == ICON_PLACEMENT . before then
369
372
add_to_end (line , { bookmark_icon })
370
373
end
371
374
@@ -374,13 +377,13 @@ function Builder:_format_line(indent_markers, arrows, icon, name, git_icons, dia
374
377
if git_icons and self .git_placement == " after" then
375
378
add_to_end (line , git_icons )
376
379
end
377
- if modified_icon and self .modified_placement == " after" then
380
+ if modified_icon and self .decorators . modified . icon_placement == ICON_PLACEMENT . after then
378
381
add_to_end (line , { modified_icon })
379
382
end
380
383
if diagnostics_icon and self .diagnostics_placement == " after" then
381
384
add_to_end (line , { diagnostics_icon })
382
385
end
383
- if bookmark_icon and self .bookmarks_placement == " after" then
386
+ if bookmark_icon and self .decorators . bookmark . icon_placement == ICON_PLACEMENT . after then
384
387
add_to_end (line , { bookmark_icon })
385
388
end
386
389
@@ -423,9 +426,8 @@ function Builder:_build_line(node, idx, num_children, unloaded_bufnr)
423
426
424
427
-- extra highighting
425
428
self :_append_highlight (node , git .get_highlight , icon .hl , name .hl )
426
- -- TODO opened
427
- self :_append_highlight (node , modified .get_highlight , icon .hl , name .hl )
428
- self :_append_highlight (node , bookmarks .get_highlight , icon .hl , name .hl )
429
+ self :_append_dec_highlight (node , self .decorators .modified , icon .hl , name .hl )
430
+ self :_append_dec_highlight (node , self .decorators .bookmark , icon .hl , name .hl )
429
431
self :_append_highlight (node , diagnostics .get_highlight , icon .hl , name .hl )
430
432
self :_append_highlight (node , copy_paste .get_highlight , icon .hl , name .hl )
431
433
0 commit comments