feat(actions): expand_all 'exclude' option (#1388)

This commit is contained in:
Krasimir Zahariev
2022-07-02 16:17:39 +00:00
committed by GitHub
parent cbbc799e6c
commit 21516f447b
3 changed files with 25 additions and 5 deletions

View File

@@ -287,6 +287,7 @@ Subsequent calls to setup will replace the previous configuration.
}, },
expand_all = { expand_all = {
max_folder_discovery = 300, max_folder_discovery = 300,
exclude = {},
}, },
open_file = { open_file = {
quit_on_open = false, quit_on_open = false,
@@ -770,11 +771,19 @@ Configuration for various actions.
Restrict changing to a directory above the global current working directory. Restrict changing to a directory above the global current working directory.
Type: `boolean`, Default: `false` Type: `boolean`, Default: `false`
*nvim-tree.actions.expand_all*
Configuration for expand_all behaviour.
*nvim-tree.actions.expand_all.max_folder_discovery* *nvim-tree.actions.expand_all.max_folder_discovery*
Limit the number of folders being explored when expanding every folders. Limit the number of folders being explored when expanding every folders.
Avoids hanging neovim when running this action on very large folders. Avoids hanging neovim when running this action on very large folders.
Type: `number`, Default: `300` Type: `number`, Default: `300`
*nvim-tree.actions.expand_all.exclude*
A list of directories that should not be expanded automatically.
E.g `{ ".git", "target", "build" }` etc.
Type: `table`, Default: `{}`
*nvim-tree.actions.open_file* *nvim-tree.actions.open_file*
Configuration options for opening a file from nvim-tree. Configuration options for opening a file from nvim-tree.

View File

@@ -540,6 +540,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
}, },
expand_all = { expand_all = {
max_folder_discovery = 300, max_folder_discovery = 300,
exclude = {},
}, },
open_file = { open_file = {
quit_on_open = false, quit_on_open = false,

View File

@@ -4,6 +4,15 @@ local utils = require "nvim-tree.utils"
local M = {} local M = {}
local function to_lookup_table(list)
local table = {}
for _, element in ipairs(list) do
table[element] = true
end
return table
end
local function expand(node) local function expand(node)
node.open = true node.open = true
if #node.nodes == 0 then if #node.nodes == 0 then
@@ -25,7 +34,7 @@ local function gen_iterator()
end end
for _, node in pairs(parent.nodes) do for _, node in pairs(parent.nodes) do
if node.nodes and not node.open then if node.nodes and not node.open and not M.EXCLUDE[node.name] then
expansion_count = expansion_count + 1 expansion_count = expansion_count + 1
expand(node) expand(node)
end end
@@ -51,6 +60,7 @@ end
function M.setup(opts) function M.setup(opts)
M.MAX_FOLDER_DISCOVERY = opts.actions.expand_all.max_folder_discovery M.MAX_FOLDER_DISCOVERY = opts.actions.expand_all.max_folder_discovery
M.EXCLUDE = to_lookup_table(opts.actions.expand_all.exclude)
end end
return M return M