refactor(#2828): multi instance nvim-tree.explorer.filters (#2841)

* refactor(#2828): multi instance nvim-tree.explorer.filters

* fix: style

* fix: apply suggestions from code review

Co-authored-by: Alexander Courtis <alex@courtis.org>

---------

Co-authored-by: Alexander Courtis <alex@courtis.org>
This commit is contained in:
Mateusz Russak
2024-07-27 05:29:27 +02:00
committed by GitHub
parent 1aa9852cad
commit 908478a0e0
8 changed files with 142 additions and 94 deletions

View File

@@ -1,7 +1,6 @@
local utils = require "nvim-tree.utils"
local builders = require "nvim-tree.explorer.node-builders"
local explorer_node = require "nvim-tree.explorer.node"
local filters = require "nvim-tree.explorer.filters"
local sorters = require "nvim-tree.explorer.sorters"
local live_filter = require "nvim-tree.live-filter"
local git = require "nvim-tree.git"
@@ -70,6 +69,10 @@ end
---@param node Node
---@param git_status table
function M.reload(node, git_status)
local explorer = require("nvim-tree.core").get_explorer()
if not explorer then
return
end
local cwd = node.link_to or node.absolute_path
local handle = vim.loop.fs_scandir(cwd)
if not handle then
@@ -78,7 +81,7 @@ function M.reload(node, git_status)
local profile = log.profile_start("reload %s", node.absolute_path)
local filter_status = filters.prepare(git_status)
local filter_status = explorer.filters:prepare(git_status)
if node.group_next then
node.nodes = { node.group_next }
@@ -100,7 +103,7 @@ function M.reload(node, git_status)
---@type uv.fs_stat.result|nil
local stat = vim.loop.fs_stat(abs)
if not filters.should_filter(abs, stat, filter_status) then
if not explorer.filters:should_filter(abs, stat, filter_status) then
remain_childs[abs] = true
-- Recreate node if type changes.