From 87961d38a7b6cd799ebe193946e86a1037ba66e8 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Mon, 9 Jan 2023 13:59:07 +1100 Subject: [PATCH 1/2] fix(#1822): test directory capable of watching before presenting it (#1901) --- lua/nvim-tree/explorer/explore.lua | 8 +++++++- lua/nvim-tree/explorer/reload.lua | 3 ++- lua/nvim-tree/watcher.lua | 25 +++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lua/nvim-tree/explorer/explore.lua b/lua/nvim-tree/explorer/explore.lua index a8aed702a54..9bacea3e187 100644 --- a/lua/nvim-tree/explorer/explore.lua +++ b/lua/nvim-tree/explorer/explore.lua @@ -6,6 +6,8 @@ local filters = require "nvim-tree.explorer.filters" local live_filter = require "nvim-tree.live-filter" local log = require "nvim-tree.log" +local Watcher = require "nvim-tree.watcher" + local M = {} local function get_type_from(type_, cwd) @@ -28,7 +30,11 @@ local function populate_children(handle, cwd, node, git_status) local ps = log.profile_start(pn) t = get_type_from(t, abs) - if not filters.should_filter(abs, filter_status) and not nodes_by_path[abs] then + if + not filters.should_filter(abs, filter_status) + and not nodes_by_path[abs] + and Watcher.is_fs_event_capable(abs) + then local child = nil if t == "directory" and vim.loop.fs_access(abs, "R") then child = builders.folder(node, abs, name) diff --git a/lua/nvim-tree/explorer/reload.lua b/lua/nvim-tree/explorer/reload.lua index 5f6a6ce419b..e7a58049414 100644 --- a/lua/nvim-tree/explorer/reload.lua +++ b/lua/nvim-tree/explorer/reload.lua @@ -8,6 +8,7 @@ local git = require "nvim-tree.git" local log = require "nvim-tree.log" local NodeIterator = require "nvim-tree.iterators.node-iterator" +local Watcher = require "nvim-tree.watcher" local M = {} @@ -86,7 +87,7 @@ function M.reload(node, git_status, unloaded_bufnr) end if not nodes_by_path[abs] then - if t == "directory" and vim.loop.fs_access(abs, "R") then + if t == "directory" and vim.loop.fs_access(abs, "R") and Watcher.is_fs_event_capable(abs) then local folder = builders.folder(node, abs, name) nodes_by_path[abs] = folder table.insert(node.nodes, folder) diff --git a/lua/nvim-tree/watcher.lua b/lua/nvim-tree/watcher.lua index b5473ca62c3..97f3a52b5f1 100644 --- a/lua/nvim-tree/watcher.lua +++ b/lua/nvim-tree/watcher.lua @@ -159,4 +159,29 @@ function M.purge_watchers() end end +--- Windows NT will present directories that cannot be enumerated. +--- Detect these by attempting to start an event monitor. +--- @param path string +--- @return boolean +function M.is_fs_event_capable(path) + if not utils.is_windows then + return true + end + + local fs_event = vim.loop.new_fs_event() + if not fs_event then + return false + end + + if fs_event:start(path, FS_EVENT_FLAGS, function() end) ~= 0 then + return false + end + + if fs_event:stop() ~= 0 then + return false + end + + return true +end + return M From fd231115c5eb992325cf919447a666e5a66f8c82 Mon Sep 17 00:00:00 2001 From: gegoune Date: Mon, 9 Jan 2023 17:53:06 +0100 Subject: [PATCH 2/2] feat(git): support `DA` state --- lua/nvim-tree/renderer/components/git.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/nvim-tree/renderer/components/git.lua b/lua/nvim-tree/renderer/components/git.lua index 31dfa049cef..fb3973c0111 100644 --- a/lua/nvim-tree/renderer/components/git.lua +++ b/lua/nvim-tree/renderer/components/git.lua @@ -39,6 +39,7 @@ local function build_icons_table(i) ["UA"] = { icons.unmerged }, [" D"] = { icons.deleted }, ["D "] = { icons.deleted }, + ["DA"] = { icons.unstaged }, ["RD"] = { icons.deleted }, ["DD"] = { icons.deleted }, ["DU"] = { icons.deleted, icons.unmerged },