Skip to content

Commit 010df50

Browse files
committed
make luacheck happy
1 parent e0961e4 commit 010df50

File tree

5 files changed

+47
-11
lines changed

5 files changed

+47
-11
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS
190190
global = false,
191191
restrict_above_cwd = false,
192192
},
193+
expand_all = {
194+
max_folder_discovery = 300,
195+
},
193196
open_file = {
194197
quit_on_open = false,
195198
resize_window = true,
@@ -261,7 +264,7 @@ require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS
261264
- Double left click acts like `<CR>`
262265
- Double right click acts like `<C-]>`
263266
- `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`).
265268
- `S` will prompt the user to enter a path and then expands the tree to match the path
266269
- `.` will enter vim command mode with the file the cursor is on
267270
- `C-k` will toggle a popup with file infos about the file under the cursor

doc/nvim-tree-lua.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ Values may be functions. Warning: this may result in unexpected behaviour.
208208
global = false,
209209
restrict_above_cwd = false,
210210
},
211+
expand_all = {
212+
max_folder_discovery = 300,
213+
},
211214
open_file = {
212215
quit_on_open = false,
213216
resize_window = true,
@@ -633,6 +636,11 @@ Configuration for various actions.
633636
Restrict changing to a directory above the global current working directory.
634637
Type: `boolean`, Default: `false`
635638

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+
636644
*nvim-tree.actions.open_file.quit_on_open*
637645
Closes the explorer when opening a file.
638646
It will also disable preventing a buffer overriding the tree.

lua/nvim-tree.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,9 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
465465
global = false,
466466
restrict_above_cwd = false,
467467
},
468+
expand_all = {
469+
max_folder_discovery = 300,
470+
},
468471
open_file = {
469472
quit_on_open = false,
470473
resize_window = true,

lua/nvim-tree/actions/expand-all.lua

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local core = require "nvim-tree.core"
22
local renderer = require "nvim-tree.renderer"
3+
local utils = require "nvim-tree.utils"
34

45
local M = {}
56

@@ -10,26 +11,46 @@ local function expand(node)
1011
end
1112
end
1213

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
1721

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)
2125
end
2226

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
2538
end
2639
end
40+
41+
return iterate
2742
end
2843

2944
function M.fn(base_node)
3045
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
3249
renderer.draw()
3350
end
3451

52+
function M.setup(opts)
53+
M.MAX_FOLDER_DISCOVERY = opts.actions.expand_all.max_folder_discovery
54+
end
55+
3556
return M

lua/nvim-tree/actions/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ function M.setup(opts)
239239
require("nvim-tree.actions.change-dir").setup(opts)
240240
require("nvim-tree.actions.copy-paste").setup(opts)
241241
require("nvim-tree.actions.create-file").setup(opts)
242+
require("nvim-tree.actions.expand-all").setup(opts)
242243

243244
local user_map_config = (opts.view or {}).mappings or {}
244245
local options = vim.tbl_deep_extend("force", DEFAULT_MAPPING_CONFIG, user_map_config)

0 commit comments

Comments
 (0)