Skip to content

fix(#1961): cycle detection on find file refresh, fix regex pattern matching on paths, do not refresh if the node is present #2010

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lua/nvim-tree/actions/finders/find-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ function M.fn(fname)

local profile = log.profile_start("find file %s", fname_real)

-- we cannot wait for watchers
reload.refresh_nodes_for_path(vim.fn.fnamemodify(fname_real, ":h"))
-- we cannot wait for watchers to populate a new node
if utils.get_node_from_path(fname_real) == nil then
reload.refresh_nodes_for_path(vim.fn.fnamemodify(fname_real, ":h"))
end

local line = core.get_nodes_starting_line()

Expand Down
12 changes: 9 additions & 3 deletions lua/nvim-tree/explorer/reload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ function M.refresh_nodes_for_path(path)

local profile = log.profile_start("refresh_nodes_for_path %s", path)

-- avoids cycles
local absolute_paths_refreshed = {}

NodeIterator.builder({ explorer })
:hidden()
:recursor(function(node)
Expand All @@ -177,10 +180,13 @@ function M.refresh_nodes_for_path(path)
end
end)
:applier(function(node)
local abs_contains = node.absolute_path and path:match("^" .. node.absolute_path)
local link_contains = node.link_to and path:match("^" .. node.link_to)
local abs_contains = node.absolute_path and path:find(node.absolute_path, 1, true) == 1
local link_contains = node.link_to and path:find(node.link_to, 1, true) == 1
if abs_contains or link_contains then
M.refresh_node(node)
if not absolute_paths_refreshed[node.absolute_path] then
absolute_paths_refreshed[node.absolute_path] = true
M.refresh_node(node)
end
end
end)
:iterate()
Expand Down