Skip to content

Commit 56ae381

Browse files
committed
node factory uses stat only
1 parent 966ef40 commit 56ae381

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

lua/nvim-tree/explorer/init.lua

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,22 +122,19 @@ function Explorer:reload(node, git_status)
122122
if filter_reason == FILTER_REASON.none then
123123
remain_childs[abs] = true
124124

125-
-- Type must come from fs_stat and not fs_scandir_next to maintain sshfs compatibility
126-
local t = stat and stat.type or nil
127-
128125
-- Recreate node if type changes.
129126
if nodes_by_path[abs] then
130127
local n = nodes_by_path[abs]
131128

132-
if n.type ~= t then
129+
if not stat or n.type ~= stat.type then
133130
utils.array_remove(node.nodes, n)
134131
n:destroy()
135132
nodes_by_path[abs] = nil
136133
end
137134
end
138135

139136
if not nodes_by_path[abs] then
140-
local new_child = node_factory.create_node(self, node, abs, t, stat, name)
137+
local new_child = node_factory.create_node(self, node, abs, stat, name)
141138
if new_child then
142139
table.insert(node.nodes, new_child)
143140
nodes_by_path[abs] = new_child
@@ -276,9 +273,7 @@ function Explorer:populate_children(handle, cwd, node, git_status, parent)
276273
local stat = vim.loop.fs_lstat(abs)
277274
local filter_reason = parent.filters:should_filter_as_reason(abs, stat, filter_status)
278275
if filter_reason == FILTER_REASON.none and not nodes_by_path[abs] then
279-
-- Type must come from fs_stat and not fs_scandir_next to maintain sshfs compatibility
280-
local t = stat and stat.type or nil
281-
local child = node_factory.create_node(self, node, abs, t, stat, name)
276+
local child = node_factory.create_node(self, node, abs, stat, name)
282277
if child then
283278
table.insert(node.nodes, child)
284279
nodes_by_path[child.absolute_path] = true

lua/nvim-tree/node/factory.lua

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,23 @@ local Watcher = require("nvim-tree.watcher")
55

66
local M = {}
77

8-
--- TODO merge #2922 and pass just stat, as stat.type from lstat is correct
9-
108
---Factory function to create the appropriate Node
119
---@param explorer Explorer
1210
---@param parent Node
1311
---@param abs string
14-
---@param t string? type from vim.loop.fs_scandir_next as stat.type is incorrectly reported as a file for links
15-
---@param stat uv.fs_stat.result?
12+
---@param stat uv.fs_stat.result? -- on nil stat return nil Node
1613
---@param name string
1714
---@return Node?
18-
function M.create_node(explorer, parent, abs, t, stat, name)
15+
function M.create_node(explorer, parent, abs, stat, name)
1916
if not stat then
2017
return nil
2118
end
2219

23-
if t == "directory" and vim.loop.fs_access(abs, "R") and Watcher.is_fs_event_capable(abs) then
20+
if stat.type == "directory" and vim.loop.fs_access(abs, "R") and Watcher.is_fs_event_capable(abs) then
2421
return DirectoryNode:create(explorer, parent, abs, name, stat)
25-
elseif t == "file" then
22+
elseif stat.type == "file" then
2623
return FileNode:create(explorer, parent, abs, name, stat)
27-
elseif t == "link" then
24+
elseif stat.type == "link" then
2825
return LinkNode:create(explorer, parent, abs, name, stat)
2926
end
3027

0 commit comments

Comments
 (0)