Skip to content

Commit 29d8c83

Browse files
committed
refactor(#2942): multi instance: move get_node_from_path to Explorer
1 parent d087a82 commit 29d8c83

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

lua/nvim-tree/actions/finders/find-file.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function M.fn(path)
3232
local profile = log.profile_start("find file %s", path_real)
3333

3434
-- refresh the contents of all parents, expanding groups as needed
35-
if utils.get_node_from_path(path_real) == nil then
35+
if explorer:get_node_from_path(path_real) == nil then
3636
explorer:refresh_parent_nodes_for_path(vim.fn.fnamemodify(path_real, ":h"))
3737
end
3838

lua/nvim-tree/explorer/init.lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,33 @@ function Explorer:find_node_line(node)
572572
return -1
573573
end
574574

575+
-- get the node in the tree state depending on the absolute path of the node
576+
-- (grouped or hidden too)
577+
---@param path string
578+
---@return Node|nil
579+
---@return number|nil
580+
function Explorer:get_node_from_path(path)
581+
582+
if self.absolute_path == path then
583+
return self
584+
end
585+
586+
return Iterator.builder(self.nodes)
587+
:hidden()
588+
:matcher(function(node)
589+
return node.absolute_path == path or node.link_to == path
590+
end)
591+
:recursor(function(node)
592+
if node.group_next then
593+
return { node.group_next }
594+
end
595+
if node.nodes then
596+
return node.nodes
597+
end
598+
end)
599+
:iterate()
600+
end
601+
575602
---Api.tree.get_nodes
576603
---@return nvim_tree.api.Node
577604
function Explorer:get_nodes()

lua/nvim-tree/git/init.lua

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,13 @@ local function reload_tree_at(toplevel)
233233
end
234234

235235
log.line("watcher", "git event executing '%s'", toplevel)
236-
local root_node = utils.get_node_from_path(toplevel)
236+
237+
local explorer = require("nvim-tree.core").get_explorer()
238+
if not explorer then
239+
return nil
240+
end
241+
242+
local root_node = explorer:get_node_from_path(toplevel)
237243
if not root_node then
238244
return
239245
end
@@ -252,7 +258,7 @@ local function reload_tree_at(toplevel)
252258
end)
253259
:iterate()
254260

255-
root_node.explorer.renderer:draw()
261+
explorer.renderer:draw()
256262
end)
257263
end
258264

0 commit comments

Comments
 (0)