Skip to content

Commit

Permalink
fix(#1961): cycle detection on refresh, preventing infinite loop (#1996)
Browse files Browse the repository at this point in the history
* #1961 diagnostic logging refresh_nodes_for_path

* #1961 add cycle detection to refresh_nodes_for_path

* #1961 escape special characters on when path matching during refresh

* #1961 escape special characters on when path matching during refresh
  • Loading branch information
alex-courtis committed Feb 14, 2023
1 parent 8b8d457 commit 4222bb8
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lua/nvim-tree/explorer/reload.lua
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 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 paths_refreshed[node.absolute_path] then
paths_refreshed[node.absolute_path] = true
M.refresh_node(node)
end
end
end)
:iterate()
Expand Down

4 comments on commit 4222bb8

@zLinz
Copy link

@zLinz zLinz commented on 4222bb8 Feb 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow this commit makes switching between my neovim files janky.

@r7vme
Copy link

@r7vme r7vme commented on 4222bb8 Feb 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar for me, on :NvimTreeFindFile whole neovim freezes for tens of seconds

@AniAggarwal
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for many of us, as in issue #1998 .
I don't know any Lua but maybe it's because paths_refreshed isn't ever cleared so it keeps getting larger and larger?

@alex-courtis
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change reverted, please accept my apologies.

Please sign in to comment.