@@ -212,9 +212,6 @@ local function async_scan(context, path)
212212 end )
213213 )
214214 else -- scan_mode == "shallow"
215- -- prepend the root path
216- -- table.insert(context.paths_to_load, 1, path)
217-
218215 context .directories_scanned = 0
219216 context .directories_to_scan = # context .paths_to_load
220217
@@ -224,45 +221,59 @@ local function async_scan(context, path)
224221
225222 -- from https://github.com/nvim-lua/plenary.nvim/blob/master/lua/plenary/scandir.lua
226223 local function read_dir (current_dir , ctx )
227- local on_fs_scandir = function (err , fd )
224+ local function on_fs_opendir (err , dir )
228225 if err then
229226 log .error (current_dir , " : " , err )
230227 else
231- while true do
232- local name , typ = uv .fs_scandir_next (fd )
233- if name == nil then
234- break
235- end
236- local entry = utils .path_join (current_dir , name )
237- local success , item = pcall (file_items .create_item , ctx , entry , typ )
238- if success then
239- if ctx .recursive and item .type == " directory" then
240- ctx .directories_to_scan = ctx .directories_to_scan + 1
241- table.insert (ctx .paths_to_load , item .path )
242- end
228+ local function on_fs_readdir (err , entries )
229+ if err then
230+ log .error (current_dir , " : " , err )
243231 else
244- log .error (" error creating item for " , path )
232+ if entries then
233+ for _ , entry in ipairs (entries ) do
234+ local success , item = pcall (
235+ file_items .create_item ,
236+ ctx ,
237+ utils .path_join (current_dir , entry .name ),
238+ entry .type
239+ )
240+ if success then
241+ if ctx .recursive and item .type == " directory" then
242+ ctx .directories_to_scan = ctx .directories_to_scan + 1
243+ table.insert (ctx .paths_to_load , item .path )
244+ end
245+ else
246+ log .error (" error creating item for " , path )
247+ end
248+ end
249+
250+ uv .fs_readdir (dir , on_fs_readdir )
251+ else
252+ uv .fs_closedir (dir )
253+ on_directory_loaded (ctx , current_dir )
254+ ctx .directories_scanned = ctx .directories_scanned + 1
255+ if ctx .directories_scanned == # ctx .paths_to_load then
256+ ctx .on_exit ()
257+ end
258+ end
245259 end
246- end
247- on_directory_loaded (ctx , current_dir )
248- ctx .directories_scanned = ctx .directories_scanned + 1
249- if ctx .directories_scanned == # ctx .paths_to_load then
250- ctx .on_exit ()
260+
261+ -- local next_path = dir_complete(ctx, current_dir)
262+ -- if next_path then
263+ -- local success, error = pcall(read_dir, next_path)
264+ -- if not success then
265+ -- log.error(next_path, ": ", error)
266+ -- end
267+ -- else
268+ -- on_exit()
269+ -- end
251270 end
252271
253- -- local next_path = dir_complete(ctx, current_dir)
254- -- if next_path then
255- -- local success, error = pcall(read_dir, next_path)
256- -- if not success then
257- -- log.error(next_path, ": ", error)
258- -- end
259- -- else
260- -- on_exit()
261- -- end
272+ uv .fs_readdir (dir , on_fs_readdir )
262273 end
263274 end
264275
265- uv .fs_scandir (current_dir , on_fs_scandir )
276+ uv .fs_opendir (current_dir , on_fs_opendir )
266277 end
267278
268279 -- local first = table.remove(context.paths_to_load)
0 commit comments