1
- local core = require " nvim-tree.core"
2
1
local notify = require " nvim-tree.notify"
3
2
local utils = require " nvim-tree.utils"
4
3
local view = require " nvim-tree.view"
@@ -41,7 +40,6 @@ local PICTURE_MAP = {
41
40
--- @field extmarks table[] extra marks for right icon placement
42
41
--- @field virtual_lines table[] virtual lines for hidden count display
43
42
--- @field private explorer Explorer
44
- --- @field private root_cwd string | nil absolute path
45
43
--- @field private index number
46
44
--- @field private depth number
47
45
--- @field private combined_groups table<string , boolean> combined group names
@@ -58,7 +56,6 @@ function Builder:new(opts, explorer)
58
56
local o = {
59
57
opts = opts ,
60
58
explorer = explorer ,
61
- root_cwd = core .get_cwd (),
62
59
index = 0 ,
63
60
depth = 0 ,
64
61
hl_args = {},
@@ -157,7 +154,7 @@ function Builder:build_folder(node)
157
154
local foldername_hl = " NvimTreeFolderName"
158
155
if node .link_to and self .opts .renderer .symlink_destination then
159
156
local arrow = icons .i .symlink_arrow
160
- local link_to = utils .path_relative (node .link_to , self .root_cwd )
157
+ local link_to = utils .path_relative (node .link_to , self .explorer . absolute_path )
161
158
foldername = string.format (" %s%s%s" , foldername , arrow , link_to )
162
159
foldername_hl = " NvimTreeSymlinkFolderName"
163
160
elseif
@@ -182,7 +179,7 @@ function Builder:build_symlink(node)
182
179
local arrow = icons .i .symlink_arrow
183
180
local symlink_formatted = node .name
184
181
if self .opts .renderer .symlink_destination then
185
- local link_to = utils .path_relative (node .link_to , self .root_cwd )
182
+ local link_to = utils .path_relative (node .link_to , self .explorer . absolute_path )
186
183
symlink_formatted = string.format (" %s%s%s" , symlink_formatted , arrow , link_to )
187
184
end
188
185
406
403
407
404
--- @private
408
405
function Builder :get_nodes_number (nodes )
409
- local explorer = core .get_explorer ()
410
- if not explorer or not explorer .live_filter .filter then
406
+ if not self .explorer .live_filter .filter then
411
407
return # nodes
412
408
end
413
409
423
419
--- @private
424
420
function Builder :build_lines (node )
425
421
if not node then
426
- node = core . get_explorer ()
422
+ node = self . explorer
427
423
end
428
424
local num_children = self :get_nodes_number (node .nodes )
429
425
local idx = 1
@@ -442,28 +438,27 @@ end
442
438
--- @return string
443
439
function Builder :format_root_name (root_label )
444
440
if type (root_label ) == " function" then
445
- local label = root_label (self .root_cwd )
441
+ local label = root_label (self .explorer . absolute_path )
446
442
if type (label ) == " string" then
447
443
return label
448
444
end
449
445
elseif type (root_label ) == " string" then
450
- return utils .path_remove_trailing (vim .fn .fnamemodify (self .root_cwd , root_label ))
446
+ return utils .path_remove_trailing (vim .fn .fnamemodify (self .explorer . absolute_path , root_label ))
451
447
end
452
448
return " ???"
453
449
end
454
450
455
451
--- @private
456
452
function Builder :build_header ()
457
- local explorer = core .get_explorer ()
458
- if view .is_root_folder_visible (core .get_cwd ()) then
453
+ if view .is_root_folder_visible (self .explorer .absolute_path ) then
459
454
local root_name = self :format_root_name (self .opts .renderer .root_folder_label )
460
455
table.insert (self .lines , root_name )
461
456
self :insert_highlight ({ " NvimTreeRootFolder" }, 0 , string.len (root_name ))
462
457
self .index = 1
463
458
end
464
459
465
- if explorer and explorer .live_filter .filter then
466
- local filter_line = string.format (" %s/%s/" , self .opts .live_filter .prefix , explorer .live_filter .filter )
460
+ if self . explorer .live_filter .filter then
461
+ local filter_line = string.format (" %s/%s/" , self .opts .live_filter .prefix , self . explorer .live_filter .filter )
467
462
table.insert (self .lines , filter_line )
468
463
local prefix_length = string.len (self .opts .live_filter .prefix )
469
464
self :insert_highlight ({ " NvimTreeLiveFilterPrefix" }, 0 , prefix_length )
0 commit comments