@@ -233,9 +233,6 @@ local function async_scan(context, path)
233233 end )
234234 )
235235 else -- scan_mode == "shallow"
236- -- prepend the root path
237- -- table.insert(context.paths_to_load, 1, path)
238-
239236 context .directories_scanned = 0
240237 context .directories_to_scan = # context .paths_to_load
241238
@@ -245,45 +242,59 @@ local function async_scan(context, path)
245242
246243 -- from https://github.com/nvim-lua/plenary.nvim/blob/master/lua/plenary/scandir.lua
247244 local function read_dir (current_dir , ctx )
248- local on_fs_scandir = function (err , fd )
245+ local function on_fs_opendir (err , dir )
249246 if err then
250247 log .error (current_dir , " : " , err )
251248 else
252- while true do
253- local name , typ = uv .fs_scandir_next (fd )
254- if name == nil then
255- break
256- end
257- local entry = utils .path_join (current_dir , name )
258- local success , item = pcall (file_items .create_item , ctx , entry , typ )
259- if success then
260- if ctx .recursive and item .type == " directory" then
261- ctx .directories_to_scan = ctx .directories_to_scan + 1
262- table.insert (ctx .paths_to_load , item .path )
263- end
249+ local function on_fs_readdir (err , entries )
250+ if err then
251+ log .error (current_dir , " : " , err )
264252 else
265- log .error (" error creating item for " , path )
253+ if entries then
254+ for _ , entry in ipairs (entries ) do
255+ local success , item = pcall (
256+ file_items .create_item ,
257+ ctx ,
258+ utils .path_join (current_dir , entry .name ),
259+ entry .type
260+ )
261+ if success then
262+ if ctx .recursive and item .type == " directory" then
263+ ctx .directories_to_scan = ctx .directories_to_scan + 1
264+ table.insert (ctx .paths_to_load , item .path )
265+ end
266+ else
267+ log .error (" error creating item for " , path )
268+ end
269+ end
270+
271+ uv .fs_readdir (dir , on_fs_readdir )
272+ else
273+ uv .fs_closedir (dir )
274+ on_directory_loaded (ctx , current_dir )
275+ ctx .directories_scanned = ctx .directories_scanned + 1
276+ if ctx .directories_scanned == # ctx .paths_to_load then
277+ ctx .on_exit ()
278+ end
279+ end
266280 end
267- end
268- on_directory_loaded (ctx , current_dir )
269- ctx .directories_scanned = ctx .directories_scanned + 1
270- if ctx .directories_scanned == # ctx .paths_to_load then
271- ctx .on_exit ()
281+
282+ -- local next_path = dir_complete(ctx, current_dir)
283+ -- if next_path then
284+ -- local success, error = pcall(read_dir, next_path)
285+ -- if not success then
286+ -- log.error(next_path, ": ", error)
287+ -- end
288+ -- else
289+ -- on_exit()
290+ -- end
272291 end
273292
274- -- local next_path = dir_complete(ctx, current_dir)
275- -- if next_path then
276- -- local success, error = pcall(read_dir, next_path)
277- -- if not success then
278- -- log.error(next_path, ": ", error)
279- -- end
280- -- else
281- -- on_exit()
282- -- end
293+ uv .fs_readdir (dir , on_fs_readdir )
283294 end
284295 end
285296
286- uv .fs_scandir (current_dir , on_fs_scandir )
297+ uv .fs_opendir (current_dir , on_fs_opendir )
287298 end
288299
289300 -- local first = table.remove(context.paths_to_load)
0 commit comments