@@ -233,9 +233,6 @@ local function async_scan(context, path)
233
233
end )
234
234
)
235
235
else -- scan_mode == "shallow"
236
- -- prepend the root path
237
- -- table.insert(context.paths_to_load, 1, path)
238
-
239
236
context .directories_scanned = 0
240
237
context .directories_to_scan = # context .paths_to_load
241
238
@@ -245,45 +242,59 @@ local function async_scan(context, path)
245
242
246
243
-- from https://github.com/nvim-lua/plenary.nvim/blob/master/lua/plenary/scandir.lua
247
244
local function read_dir (current_dir , ctx )
248
- local on_fs_scandir = function (err , fd )
245
+ local function on_fs_opendir (err , dir )
249
246
if err then
250
247
log .error (current_dir , " : " , err )
251
248
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 )
264
252
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
266
280
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
272
291
end
273
292
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 )
283
294
end
284
295
end
285
296
286
- uv .fs_scandir (current_dir , on_fs_scandir )
297
+ uv .fs_opendir (current_dir , on_fs_opendir )
287
298
end
288
299
289
300
-- local first = table.remove(context.paths_to_load)
0 commit comments