@@ -106,6 +106,26 @@ local render_context = function(context)
106
106
context = nil
107
107
end
108
108
109
+ local job_complete_async = function (context )
110
+ local state = context .state
111
+ local parent_id = context .parent_id
112
+ if # context .all_items == 0 then
113
+ log .info (" No items, skipping git ignored/status lookups" )
114
+ elseif state .filtered_items .hide_gitignored or state .enable_git_status then
115
+ local mark_ignored_async = async .wrap (function (_state , _all_items , _callback )
116
+ git .mark_ignored (_state , _all_items , _callback )
117
+ end , 3 )
118
+ local all_items = mark_ignored_async (state , context .all_items )
119
+
120
+ if parent_id then
121
+ vim .list_extend (state .git_ignored , all_items )
122
+ else
123
+ state .git_ignored = all_items
124
+ end
125
+ end
126
+ return context
127
+ end
128
+
109
129
local job_complete = function (context )
110
130
local state = context .state
111
131
local parent_id = context .parent_id
@@ -135,8 +155,8 @@ local job_complete = function(context)
135
155
state .git_ignored = all_items
136
156
end
137
157
end
158
+ render_context (context )
138
159
end
139
- render_context (context )
140
160
end
141
161
142
162
local function create_node (context , node )
@@ -199,26 +219,34 @@ local function scan_dir_sync(context, path)
199
219
end
200
220
end
201
221
202
- local function scan_dir_async (context , path , callback )
203
- get_children_async (path , function (children )
204
- for _ , child in ipairs (children ) do
205
- create_node (context , child )
206
- if child .type == " directory" then
207
- local grandchild_nodes = get_children_sync (child .path )
208
- if
209
- grandchild_nodes == nil
210
- or # grandchild_nodes == 0
211
- or # grandchild_nodes == 1 and grandchild_nodes [1 ].type == " directory"
212
- then
213
- scan_dir_sync (context , child .path )
214
- end
222
+ local function scan_dir_async (context , path )
223
+ log .debug (" scan_dir_async - start " .. path )
224
+
225
+ local get_children = async .wrap (function (callback )
226
+ return get_children_async (path , callback )
227
+ end , 1 )
228
+
229
+ local children = get_children ()
230
+ for _ , child in ipairs (children ) do
231
+ create_node (context , child )
232
+ if child .type == " directory" then
233
+ local grandchild_nodes = get_children_sync (child .path )
234
+ if
235
+ grandchild_nodes == nil
236
+ or # grandchild_nodes == 0
237
+ or # grandchild_nodes == 1 and grandchild_nodes [1 ].type == " directory"
238
+ then
239
+ scan_dir_sync (context , child .path )
215
240
end
216
241
end
217
- process_node (context , path )
218
- callback (path )
219
- end )
242
+ end
243
+
244
+ log .debug (" scan_dir_async - finish " .. path )
245
+ process_node (context , path )
246
+ return path
220
247
end
221
248
249
+
222
250
-- async_scan scans all the directories in context.paths_to_load
223
251
-- and adds them as items to render in the UI.
224
252
local function async_scan (context , path )
@@ -229,7 +257,9 @@ local function async_scan(context, path)
229
257
local scan_tasks = {}
230
258
for _ , p in ipairs (context .paths_to_load ) do
231
259
local scan_task = async .wrap (function (callback )
232
- scan_dir_async (context , p , callback )
260
+ async .run (function ()
261
+ scan_dir_async (context , p )
262
+ end , callback )
233
263
end , 1 )
234
264
table.insert (scan_tasks , scan_task )
235
265
end
@@ -471,7 +501,6 @@ M.get_items = function(state, parent_id, path_to_reveal, callback, async, recurs
471
501
context .path_to_reveal = path_to_reveal
472
502
context .recursive = recursive
473
503
context .callback = callback
474
-
475
504
-- Create root folder
476
505
local root = file_items .create_item (context , parent_id or state .path , " directory" )
477
506
root .name = vim .fn .fnamemodify (root .path , " :~" )
@@ -490,6 +519,62 @@ M.get_items = function(state, parent_id, path_to_reveal, callback, async, recurs
490
519
end
491
520
end
492
521
522
+ -- async method
523
+ M .get_dir_items_async = function (state , parent_id , recursive )
524
+ local context = file_items .create_context ()
525
+ context .state = state
526
+ context .parent_id = parent_id
527
+ context .path_to_reveal = nil
528
+ context .recursive = recursive
529
+ context .callback = nil
530
+ context .paths_to_load = {}
531
+
532
+ -- Create root folder
533
+ local root = file_items .create_item (context , parent_id or state .path , " directory" )
534
+ root .name = vim .fn .fnamemodify (root .path , " :~" )
535
+ root .loaded = true
536
+ root .search_pattern = state .search_pattern
537
+ context .root = root
538
+ context .folders [root .path ] = root
539
+ state .default_expanded_nodes = state .force_open_folders or { state .path }
540
+
541
+ local filtered_items = state .filtered_items or {}
542
+ context .is_a_never_show_file = function (fname )
543
+ if fname then
544
+ local _ , name = utils .split_path (fname )
545
+ if name then
546
+ if filtered_items .never_show and filtered_items .never_show [name ] then
547
+ return true
548
+ end
549
+ if utils .is_filtered_by_pattern (filtered_items .never_show_by_pattern , fname , name ) then
550
+ return true
551
+ end
552
+ end
553
+ end
554
+ return false
555
+ end
556
+ table.insert (context .paths_to_load , parent_id )
557
+
558
+ local scan_tasks = {}
559
+ for _ , p in ipairs (context .paths_to_load ) do
560
+ local scan_task = function ()
561
+ scan_dir_async (context , p )
562
+ end
563
+ table.insert (scan_tasks , scan_task )
564
+ end
565
+ async .util .join (scan_tasks )
566
+
567
+ job_complete_async (context )
568
+
569
+ local finalize = async .wrap (function (_context , _callback )
570
+ vim .schedule (function ()
571
+ render_context (_context )
572
+ _callback ()
573
+ end )
574
+ end , 2 )
575
+ finalize (context )
576
+ end
577
+
493
578
M .stop_watchers = function (state )
494
579
if state .use_libuv_file_watcher and state .tree then
495
580
-- We are loaded a new root or refreshing, unwatch any folders that were
0 commit comments