From 569e6a2883dd46e3d215496cce4e9a393c0e65b2 Mon Sep 17 00:00:00 2001 From: mxple Date: Sun, 1 Sep 2024 18:12:49 -0400 Subject: [PATCH 1/4] add type fallback for nil types --- lua/nvim-tree/explorer/explore.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/nvim-tree/explorer/explore.lua b/lua/nvim-tree/explorer/explore.lua index da7c1b32e8c..3c2ba740100 100644 --- a/lua/nvim-tree/explorer/explore.lua +++ b/lua/nvim-tree/explorer/explore.lua @@ -35,6 +35,7 @@ local function populate_children(handle, cwd, node, git_status, parent) end local abs = utils.path_join { cwd, name } + t = t or (vim.loop.fs_stat(abs) or {}).type if Watcher.is_fs_event_capable(abs) then local profile = log.profile_start("explore populate_children %s", abs) From d95891c0a3ee341730f4c600c0718accc02ee1a8 Mon Sep 17 00:00:00 2001 From: mxple Date: Mon, 2 Sep 2024 02:44:07 -0400 Subject: [PATCH 2/4] add PR suggestions --- lua/nvim-tree/explorer/explore.lua | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lua/nvim-tree/explorer/explore.lua b/lua/nvim-tree/explorer/explore.lua index 3c2ba740100..341de3e4084 100644 --- a/lua/nvim-tree/explorer/explore.lua +++ b/lua/nvim-tree/explorer/explore.lua @@ -29,27 +29,30 @@ local function populate_children(handle, cwd, node, git_status, parent) }) while true do - local name, t = vim.loop.fs_scandir_next(handle) + local name, _ = vim.loop.fs_scandir_next(handle) if not name then break end local abs = utils.path_join { cwd, name } - t = t or (vim.loop.fs_stat(abs) or {}).type if Watcher.is_fs_event_capable(abs) then local profile = log.profile_start("explore populate_children %s", abs) ---@type uv.fs_stat.result|nil local stat = vim.loop.fs_stat(abs) + + -- Type must come from fs_stat and not fs_scandir_next to maintain sshfs compatibility + local type = (vim.loop.fs_stat(abs) or {}).type + local filter_reason = parent.filters:should_filter_as_reason(abs, stat, filter_status) if filter_reason == FILTER_REASON.none and not nodes_by_path[abs] then local child = nil - if t == "directory" and vim.loop.fs_access(abs, "R") then + if type == "directory" and vim.loop.fs_access(abs, "R") then child = builders.folder(node, abs, name, stat) - elseif t == "file" then + elseif type == "file" then child = builders.file(node, abs, name, stat) - elseif t == "link" then + elseif type == "link" then local link = builders.link(node, abs, name, stat) if link.link_to ~= nil then child = link From 2e49425f6d6c3ce6d1369898dda6a1d6877c2bc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20=E6=9D=8E?= <83033020+mxple@users.noreply.github.com> Date: Fri, 6 Sep 2024 10:22:59 -0400 Subject: [PATCH 3/4] Update lua/nvim-tree/explorer/explore.lua Co-authored-by: Alexander Courtis --- lua/nvim-tree/explorer/explore.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/nvim-tree/explorer/explore.lua b/lua/nvim-tree/explorer/explore.lua index 341de3e4084..4395426e28e 100644 --- a/lua/nvim-tree/explorer/explore.lua +++ b/lua/nvim-tree/explorer/explore.lua @@ -43,7 +43,7 @@ local function populate_children(handle, cwd, node, git_status, parent) local stat = vim.loop.fs_stat(abs) -- Type must come from fs_stat and not fs_scandir_next to maintain sshfs compatibility - local type = (vim.loop.fs_stat(abs) or {}).type + local type = stat and stat.type or nil local filter_reason = parent.filters:should_filter_as_reason(abs, stat, filter_status) if filter_reason == FILTER_REASON.none and not nodes_by_path[abs] then From d45a16b5e00c186e14af7df7156339b0dd0a8607 Mon Sep 17 00:00:00 2001 From: mxple Date: Sun, 8 Sep 2024 16:01:43 -0400 Subject: [PATCH 4/4] use type from fs_stat for sshfs compatibility --- lua/nvim-tree/actions/fs/remove-file.lua | 9 +++++++-- lua/nvim-tree/explorer/init.lua | 13 ++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lua/nvim-tree/actions/fs/remove-file.lua b/lua/nvim-tree/actions/fs/remove-file.lua index 3ff5877bb54..fa17039e72b 100644 --- a/lua/nvim-tree/actions/fs/remove-file.lua +++ b/lua/nvim-tree/actions/fs/remove-file.lua @@ -56,13 +56,18 @@ local function remove_dir(cwd) end while true do - local name, t = vim.loop.fs_scandir_next(handle) + local name, _ = vim.loop.fs_scandir_next(handle) if not name then break end local new_cwd = utils.path_join { cwd, name } - if t == "directory" then + + -- Type must come from fs_stat and not fs_scandir_next to maintain sshfs compatibility + local stat = vim.loop.fs_stat(new_cwd) + local type = stat and stat.type or nil + + if type == "directory" then local success = remove_dir(new_cwd) if not success then return false diff --git a/lua/nvim-tree/explorer/init.lua b/lua/nvim-tree/explorer/init.lua index f6cdbcaaaa0..cdfb0d5aeec 100644 --- a/lua/nvim-tree/explorer/init.lua +++ b/lua/nvim-tree/explorer/init.lua @@ -119,7 +119,7 @@ function Explorer:reload(node, git_status) }) while true do - local name, t = vim.loop.fs_scandir_next(handle) + local name, _ = vim.loop.fs_scandir_next(handle) if not name then break end @@ -132,11 +132,14 @@ function Explorer:reload(node, git_status) if filter_reason == FILTER_REASON.none then remain_childs[abs] = true + -- Type must come from fs_stat and not fs_scandir_next to maintain sshfs compatibility + local type = stat and stat.type or nil + -- Recreate node if type changes. if nodes_by_path[abs] then local n = nodes_by_path[abs] - if n.type ~= t then + if n.type ~= type then utils.array_remove(node.nodes, n) explorer_node.node_destroy(n) nodes_by_path[abs] = nil @@ -145,11 +148,11 @@ function Explorer:reload(node, git_status) if not nodes_by_path[abs] then local new_child = nil - if t == "directory" and vim.loop.fs_access(abs, "R") and Watcher.is_fs_event_capable(abs) then + if type == "directory" and vim.loop.fs_access(abs, "R") and Watcher.is_fs_event_capable(abs) then new_child = builders.folder(node, abs, name, stat) - elseif t == "file" then + elseif type == "file" then new_child = builders.file(node, abs, name, stat) - elseif t == "link" then + elseif type == "link" then local link = builders.link(node, abs, name, stat) if link.link_to ~= nil then new_child = link