fix(#2293): remove unnecessary git status during find file (#2294)

This commit is contained in:
Alexander Courtis
2023-07-01 11:28:20 +10:00
committed by GitHub
parent 3cc698b35b
commit 1fe32286db
2 changed files with 3 additions and 45 deletions

View File

@@ -3,7 +3,6 @@ local view = require "nvim-tree.view"
local utils = require "nvim-tree.utils"
local renderer = require "nvim-tree.renderer"
local core = require "nvim-tree.core"
local reload = require "nvim-tree.explorer.reload"
local Iterator = require "nvim-tree.iterators.node-iterator"
local M = {}
@@ -30,10 +29,8 @@ function M.fn(path)
local profile = log.profile_start("find file %s", path_real)
-- we cannot wait for watchers to populate a new node
if utils.get_node_from_path(path_real) == nil then
reload.refresh_nodes_for_path(vim.fn.fnamemodify(path_real, ":h"))
end
-- force a re-expand when the node is not in the tree
local node_present = utils.get_node_from_path(path_real) ~= nil
local line = core.get_nodes_starting_line()
@@ -60,7 +57,7 @@ function M.fn(path)
if not node.group_next then
node.open = true
end
if #node.nodes == 0 then
if #node.nodes == 0 or not node_present then
core.get_explorer():expand(node)
end
end

View File

@@ -7,7 +7,6 @@ local live_filter = require "nvim-tree.live-filter"
local git = require "nvim-tree.git"
local log = require "nvim-tree.log"
local NodeIterator = require "nvim-tree.iterators.node-iterator"
local Watcher = require "nvim-tree.watcher"
local M = {}
@@ -178,44 +177,6 @@ function M.refresh_node(node, callback)
end
end
---Refresh contents and git status for all nodes to a path: actual directory and links
---@param path string absolute path
function M.refresh_nodes_for_path(path)
local explorer = require("nvim-tree.core").get_explorer()
if not explorer then
return
end
local profile = log.profile_start("refresh_nodes_for_path %s", path)
-- avoids cycles
local absolute_paths_refreshed = {}
NodeIterator.builder({ explorer })
:hidden()
:recursor(function(node)
if node.group_next then
return { node.group_next }
end
if node.nodes then
return node.nodes
end
end)
:applier(function(node)
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
if not absolute_paths_refreshed[node.absolute_path] then
absolute_paths_refreshed[node.absolute_path] = true
M.refresh_node(node)
end
end
end)
:iterate()
log.profile_end(profile)
end
function M.setup(opts)
M.config = opts.renderer
end