feat(view): add filters.git_clean, filters.no_buffer (#1784)

* feat(view): add filters.git_clean

* feat(view): add filters.git_clean

* feat(view): add filters.no_buffer

* feat(view): filters.no_buffer misses unloaded, handles buffer in/out

* feat(view): filters.no_buffer matches directories specifically

* feat(view): filters.no_buffer clarify targets

* feat: add placeholder filters.diagnostics_ok, refactor filters

* feat(view): remove placeholder filters.diagnostics_ok
This commit is contained in:
Alexander Courtis
2022-12-10 15:55:33 +11:00
committed by GitHub
parent e49fa4e529
commit c5dc80c36b
12 changed files with 214 additions and 77 deletions

View File

@@ -12,6 +12,8 @@ local Actions = {
toggle_dotfiles = require("nvim-tree.actions.tree-modifiers.toggles").dotfiles,
toggle_custom = require("nvim-tree.actions.tree-modifiers.toggles").custom,
toggle_git_ignored = require("nvim-tree.actions.tree-modifiers.toggles").git_ignored,
toggle_git_clean = require("nvim-tree.actions.tree-modifiers.toggles").git_clean,
toggle_no_buffer = require("nvim-tree.actions.tree-modifiers.toggles").no_buffer,
-- Filesystem operations
copy_absolute_path = require("nvim-tree.actions.fs.copy-paste").copy_absolute_path,

View File

@@ -14,6 +14,8 @@ local function search(search_dir, input_path)
local function iter(dir)
local realpath, path, name, stat, handle, _
local filter_status = filters.prepare()
handle, _ = vim.loop.fs_scandir(dir)
if not handle then
return
@@ -34,7 +36,7 @@ local function search(search_dir, input_path)
break
end
if not filters.should_ignore(path) then
if not filters.should_filter(path, filter_status) then
if string.find(path, "/" .. input_path .. "$") then
return path
end

View File

@@ -76,6 +76,11 @@ local DEFAULT_MAPPINGS = {
action = "last_sibling",
desc = "navigate to the last sibling of current file/directory",
},
{
key = "C",
action = "toggle_git_clean",
desc = "toggle visibility of git clean via |filters.git_clean| option",
},
{
key = "I",
action = "toggle_git_ignored",
@@ -86,6 +91,11 @@ local DEFAULT_MAPPINGS = {
action = "toggle_dotfiles",
desc = "toggle visibility of dotfiles via |filters.dotfiles| option",
},
{
key = "B",
action = "toggle_no_buffer",
desc = "toggle visibility of files/folders hidden via |filters.no_buffer| option",
},
{
key = "U",
action = "toggle_custom",

View File

@@ -6,13 +6,13 @@ local core = require "nvim-tree.core"
local M = {}
local function refresh_nodes(node, projects)
local function refresh_nodes(node, projects, unloaded_bufnr)
local cwd = node.cwd or node.link_to or node.absolute_path
local project_root = git.get_project_root(cwd)
explorer_module.reload(node, projects[project_root] or {})
explorer_module.reload(node, projects[project_root] or {}, unloaded_bufnr)
for _, _node in ipairs(node.nodes) do
if _node.nodes and _node.open then
refresh_nodes(_node, projects)
refresh_nodes(_node, projects, unloaded_bufnr)
end
end
end
@@ -33,14 +33,16 @@ function M.reload_node_status(parent_node, projects)
end
local event_running = false
function M.reload_explorer()
---@param _ table unused node passed by action
---@param unloaded_bufnr number optional bufnr recently unloaded via BufUnload event
function M.reload_explorer(_, unloaded_bufnr)
if event_running or not core.get_explorer() or vim.v.exiting ~= vim.NIL then
return
end
event_running = true
local projects = git.reload()
refresh_nodes(core.get_explorer(), projects)
refresh_nodes(core.get_explorer(), projects, unloaded_bufnr)
if view.is_visible() then
renderer.draw()
end

View File

@@ -15,6 +15,16 @@ function M.git_ignored()
return reloaders.reload_explorer()
end
function M.git_clean()
filters.config.filter_git_clean = not filters.config.filter_git_clean
return reloaders.reload_explorer()
end
function M.no_buffer()
filters.config.filter_no_buffer = not filters.config.filter_no_buffer
return reloaders.reload_explorer()
end
function M.dotfiles()
filters.config.filter_dotfiles = not filters.config.filter_dotfiles
return reloaders.reload_explorer()