File tree Expand file tree Collapse file tree 5 files changed +47
-11
lines changed Expand file tree Collapse file tree 5 files changed +47
-11
lines changed Original file line number Diff line number Diff line change @@ -190,6 +190,9 @@ require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS
190
190
global = false ,
191
191
restrict_above_cwd = false ,
192
192
},
193
+ expand_all = {
194
+ max_folder_discovery = 300 ,
195
+ },
193
196
open_file = {
194
197
quit_on_open = false ,
195
198
resize_window = true ,
@@ -261,7 +264,7 @@ require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS
261
264
- Double left click acts like ` <CR> `
262
265
- Double right click acts like ` <C-]> `
263
266
- ` W ` will collapse the whole tree
264
- - ` E ` will expand the whole tree. Be aware this might hang neovim for a while if running on a big folder (such as home dir or root dir ).
267
+ - ` E ` will expand the whole tree. Be aware this might hang neovim for a while if running on a big folder (see ` :help nvim-tree.actions.expand_all.max_folder_discovery ` ).
265
268
- ` S ` will prompt the user to enter a path and then expands the tree to match the path
266
269
- ` . ` will enter vim command mode with the file the cursor is on
267
270
- ` C-k ` will toggle a popup with file infos about the file under the cursor
Original file line number Diff line number Diff line change @@ -208,6 +208,9 @@ Values may be functions. Warning: this may result in unexpected behaviour.
208
208
global = false,
209
209
restrict_above_cwd = false,
210
210
},
211
+ expand_all = {
212
+ max_folder_discovery = 300,
213
+ },
211
214
open_file = {
212
215
quit_on_open = false,
213
216
resize_window = true,
@@ -633,6 +636,11 @@ Configuration for various actions.
633
636
Restrict changing to a directory above the global current working directory.
634
637
Type: `boolean ` , Default: `false`
635
638
639
+ *nvim-tree.actions.expand_all.max_folder_discovery*
640
+ Limit the number of folders being explored when expanding every folders.
641
+ Avoids hanging neovim when running this action on very large folders.
642
+ Type: `number ` , Default: `300 `
643
+
636
644
*nvim-tree.actions.open_file.quit_on_open*
637
645
Closes the explorer when opening a file.
638
646
It will also disable preventing a buffer overriding the tree.
Original file line number Diff line number Diff line change @@ -465,6 +465,9 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
465
465
global = false ,
466
466
restrict_above_cwd = false ,
467
467
},
468
+ expand_all = {
469
+ max_folder_discovery = 300 ,
470
+ },
468
471
open_file = {
469
472
quit_on_open = false ,
470
473
resize_window = true ,
Original file line number Diff line number Diff line change 1
1
local core = require " nvim-tree.core"
2
2
local renderer = require " nvim-tree.renderer"
3
+ local utils = require " nvim-tree.utils"
3
4
4
5
local M = {}
5
6
@@ -10,26 +11,46 @@ local function expand(node)
10
11
end
11
12
end
12
13
13
- local function iterate (_node )
14
- if _node .parent and _node .nodes and not _node .open then
15
- expand (_node )
16
- end
14
+ local function gen_iterator ()
15
+ local expansion_count = 0
16
+
17
+ local function iterate (parent )
18
+ if expansion_count >= M .MAX_FOLDER_DISCOVERY then
19
+ return true
20
+ end
17
21
18
- for _ , node in pairs ( _node .nodes ) do
19
- if node . nodes and not node . open then
20
- expand (node )
22
+ if parent . parent and parent .nodes and not parent . open then
23
+ expansion_count = expansion_count + 1
24
+ expand (parent )
21
25
end
22
26
23
- if node .open then
24
- iterate (node )
27
+ for _ , node in pairs (parent .nodes ) do
28
+ if node .nodes and not node .open then
29
+ expansion_count = expansion_count + 1
30
+ expand (node )
31
+ end
32
+
33
+ if node .open then
34
+ if iterate (node ) then
35
+ return true
36
+ end
37
+ end
25
38
end
26
39
end
40
+
41
+ return iterate
27
42
end
28
43
29
44
function M .fn (base_node )
30
45
local node = base_node .nodes and base_node or core .get_explorer ()
31
- iterate (node )
46
+ if gen_iterator ()(node ) then
47
+ utils .warn (" expansion iteration was halted after " .. M .MAX_FOLDER_DISCOVERY .. " discovered folders" )
48
+ end
32
49
renderer .draw ()
33
50
end
34
51
52
+ function M .setup (opts )
53
+ M .MAX_FOLDER_DISCOVERY = opts .actions .expand_all .max_folder_discovery
54
+ end
55
+
35
56
return M
Original file line number Diff line number Diff line change @@ -239,6 +239,7 @@ function M.setup(opts)
239
239
require (" nvim-tree.actions.change-dir" ).setup (opts )
240
240
require (" nvim-tree.actions.copy-paste" ).setup (opts )
241
241
require (" nvim-tree.actions.create-file" ).setup (opts )
242
+ require (" nvim-tree.actions.expand-all" ).setup (opts )
242
243
243
244
local user_map_config = (opts .view or {}).mappings or {}
244
245
local options = vim .tbl_deep_extend (" force" , DEFAULT_MAPPING_CONFIG , user_map_config )
You can’t perform that action at this time.
0 commit comments