Skip to content

Commit 4222bb8

Browse files
authored
fix(#1961): cycle detection on refresh, preventing infinite loop (#1996)
* #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
1 parent 8b8d457 commit 4222bb8

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lua/nvim-tree/explorer/reload.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ function M.refresh_nodes_for_path(path)
166166

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

169+
-- avoids cycles
170+
local paths_refreshed = {}
171+
169172
NodeIterator.builder({ explorer })
170173
:hidden()
171174
:recursor(function(node)
@@ -177,10 +180,13 @@ function M.refresh_nodes_for_path(path)
177180
end
178181
end)
179182
:applier(function(node)
180-
local abs_contains = node.absolute_path and path:match("^" .. node.absolute_path)
181-
local link_contains = node.link_to and path:match("^" .. node.link_to)
183+
local abs_contains = node.absolute_path and path:find(node.absolute_path, 1, true) ~= 1
184+
local link_contains = node.link_to and path:find(node.link_to, 1, true) ~= 1
182185
if abs_contains or link_contains then
183-
M.refresh_node(node)
186+
if not paths_refreshed[node.absolute_path] then
187+
paths_refreshed[node.absolute_path] = true
188+
M.refresh_node(node)
189+
end
184190
end
185191
end)
186192
:iterate()

0 commit comments

Comments
 (0)