From 21516f447baf42f6f11421a017cd69306d5d5ff3 Mon Sep 17 00:00:00 2001 From: Krasimir Zahariev <34000763+KrasimirZahariev@users.noreply.github.com> Date: Sat, 2 Jul 2022 16:17:39 +0000 Subject: [PATCH] feat(actions): expand_all 'exclude' option (#1388) --- doc/nvim-tree-lua.txt | 17 +++++++++++++---- lua/nvim-tree.lua | 1 + lua/nvim-tree/actions/expand-all.lua | 12 +++++++++++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 7844bf7a..5a12ca46 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -287,6 +287,7 @@ Subsequent calls to setup will replace the previous configuration. }, expand_all = { max_folder_discovery = 300, + exclude = {}, }, open_file = { quit_on_open = false, @@ -770,10 +771,18 @@ Configuration for various actions. Restrict changing to a directory above the global current working directory. Type: `boolean`, Default: `false` - *nvim-tree.actions.expand_all.max_folder_discovery* - Limit the number of folders being explored when expanding every folders. - Avoids hanging neovim when running this action on very large folders. - Type: `number`, Default: `300` + *nvim-tree.actions.expand_all* + Configuration for expand_all behaviour. + + *nvim-tree.actions.expand_all.max_folder_discovery* + Limit the number of folders being explored when expanding every folders. + Avoids hanging neovim when running this action on very large folders. + 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* Configuration options for opening a file from nvim-tree. diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index c1e05338..73ac6d88 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -540,6 +540,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS }, expand_all = { max_folder_discovery = 300, + exclude = {}, }, open_file = { quit_on_open = false, diff --git a/lua/nvim-tree/actions/expand-all.lua b/lua/nvim-tree/actions/expand-all.lua index 2b5db1b2..57a20588 100644 --- a/lua/nvim-tree/actions/expand-all.lua +++ b/lua/nvim-tree/actions/expand-all.lua @@ -4,6 +4,15 @@ local utils = require "nvim-tree.utils" 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) node.open = true if #node.nodes == 0 then @@ -25,7 +34,7 @@ local function gen_iterator() end 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 expand(node) end @@ -51,6 +60,7 @@ end function M.setup(opts) M.MAX_FOLDER_DISCOVERY = opts.actions.expand_all.max_folder_discovery + M.EXCLUDE = to_lookup_table(opts.actions.expand_all.exclude) end return M