@@ -7,6 +7,7 @@ local live_filter = require "nvim-tree.live-filter"
7
7
local git = require " nvim-tree.git"
8
8
local log = require " nvim-tree.log"
9
9
10
+ local NodeIterator = require " nvim-tree.iterators.node-iterator"
10
11
local Watcher = require " nvim-tree.watcher"
11
12
12
13
local M = {}
@@ -160,6 +161,44 @@ function M.refresh_node(node, callback)
160
161
end )
161
162
end
162
163
164
+ --- Refresh contents of all nodes to a path: actual directory and links.
165
+ --- Groups will be expanded if needed.
166
+ --- @param path string absolute path
167
+ function M .refresh_parent_nodes_for_path (path )
168
+ local explorer = require (" nvim-tree.core" ).get_explorer ()
169
+ if not explorer then
170
+ return
171
+ end
172
+
173
+ local profile = log .profile_start (" refresh_parent_nodes_for_path %s" , path )
174
+
175
+ -- collect parent nodes from the top down
176
+ local parent_nodes = {}
177
+ NodeIterator .builder ({ explorer })
178
+ :recursor (function (node )
179
+ return node .nodes
180
+ end )
181
+ :applier (function (node )
182
+ local abs_contains = node .absolute_path and path :find (node .absolute_path , 1 , true ) == 1
183
+ local link_contains = node .link_to and path :find (node .link_to , 1 , true ) == 1
184
+ if abs_contains or link_contains then
185
+ table.insert (parent_nodes , node )
186
+ end
187
+ end )
188
+ :iterate ()
189
+
190
+ -- refresh in order; this will expand groups as needed
191
+ for _ , node in ipairs (parent_nodes ) do
192
+ local project_root = git .get_project_root (node .absolute_path )
193
+ local project = git .get_project (project_root ) or {}
194
+
195
+ M .reload (node , project )
196
+ update_parent_statuses (node , project , project_root )
197
+ end
198
+
199
+ log .profile_end (profile )
200
+ end
201
+
163
202
function M .setup (opts )
164
203
M .config = opts .renderer
165
204
end
0 commit comments