Skip to content

Commit cf7fb58

Browse files
committed
fix(#1520) file type changes are not detected.
1 parent 09a5126 commit cf7fb58

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lua/nvim-tree/explorer/node-builders.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function M.folder(parent, absolute_path, name)
1111
local has_children = handle and uv.fs_scandir_next(handle) ~= nil
1212

1313
return {
14+
type = "directory",
1415
absolute_path = absolute_path,
1516
fs_stat = uv.fs_stat(absolute_path),
1617
group_next = nil, -- If node is grouped, this points to the next child dir/link node
@@ -34,6 +35,7 @@ function M.file(parent, absolute_path, name)
3435
local ext = string.match(name, ".?[^.]+%.(.*)") or ""
3536

3637
return {
38+
type = "file",
3739
absolute_path = absolute_path,
3840
executable = M.is_executable(absolute_path, ext),
3941
extension = ext,
@@ -61,6 +63,7 @@ function M.link(parent, absolute_path, name)
6163
end
6264

6365
return {
66+
type = "link",
6467
absolute_path = absolute_path,
6568
fs_stat = uv.fs_stat(absolute_path),
6669
group_next = nil, -- If node is grouped, this points to the next child dir/link node

lua/nvim-tree/explorer/reload.lua

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ local function update_status(nodes_by_path, node_ignored, status)
1818
end
1919
end
2020

21+
local function table_find(table, value)
22+
for i, v in ipairs(table) do
23+
if v == value then
24+
return i
25+
end
26+
end
27+
return nil
28+
end
29+
2130
function M.reload(node, status)
2231
local cwd = node.link_to or node.absolute_path
2332
local handle = uv.fs_scandir(cwd)
@@ -45,6 +54,20 @@ function M.reload(node, status)
4554
t = t or (uv.fs_stat(abs) or {}).type
4655
if not filters.should_ignore(abs) and not filters.should_ignore_git(abs, status.files) then
4756
child_names[abs] = true
57+
58+
-- Recreate node if type changes.
59+
if nodes_by_path[abs] then
60+
local n = nodes_by_path[abs]
61+
62+
if n.type ~= t then
63+
local idx = table_find(node.nodes, n)
64+
if idx then
65+
table.remove(node.nodes, idx)
66+
end
67+
nodes_by_path[abs] = nil
68+
end
69+
end
70+
4871
if not nodes_by_path[abs] then
4972
if t == "directory" and uv.fs_access(abs, "R") then
5073
local folder = builders.folder(node, abs, name)

0 commit comments

Comments
 (0)