@@ -127,45 +127,59 @@ local function async_scan(context, path)
127127
128128 -- from https://github.com/nvim-lua/plenary.nvim/blob/master/lua/plenary/scandir.lua
129129 local function read_dir (current_dir , ctx )
130- local on_fs_scandir = function (err , fd )
130+ local function on_fs_opendir (err , dir )
131131 if err then
132132 log .error (current_dir , " : " , err )
133133 else
134- while true do
135- local name , typ = uv .fs_scandir_next (fd )
136- if name == nil then
137- break
138- end
139- local entry = utils .path_join (current_dir , name )
140- local success , item = pcall (file_items .create_item , ctx , entry , typ )
141- if success then
142- if ctx .recursive and item .type == " directory" then
143- ctx .directories_to_scan = ctx .directories_to_scan + 1
144- table.insert (ctx .paths_to_load , item .path )
145- end
134+ local function on_fs_readdir (err , entries )
135+ if err then
136+ log .error (current_dir , " : " , err )
146137 else
147- log .error (" error creating item for " , path )
138+ if entries then
139+ for _ , entry in ipairs (entries ) do
140+ local success , item = pcall (
141+ file_items .create_item ,
142+ ctx ,
143+ utils .path_join (current_dir , entry .name ),
144+ entry .type
145+ )
146+ if success then
147+ if ctx .recursive and item .type == " directory" then
148+ ctx .directories_to_scan = ctx .directories_to_scan + 1
149+ table.insert (ctx .paths_to_load , item .path )
150+ end
151+ else
152+ log .error (" error creating item for " , path )
153+ end
154+ end
155+
156+ uv .fs_readdir (dir , on_fs_readdir )
157+ else
158+ uv .fs_closedir (dir )
159+ on_directory_loaded (ctx , current_dir )
160+ ctx .directories_scanned = ctx .directories_scanned + 1
161+ if ctx .directories_scanned == # ctx .paths_to_load then
162+ ctx .on_exit ()
163+ end
164+ end
148165 end
149- end
150- on_directory_loaded (ctx , current_dir )
151- ctx .directories_scanned = ctx .directories_scanned + 1
152- if ctx .directories_scanned == # ctx .paths_to_load then
153- ctx .on_exit ()
166+
167+ -- local next_path = dir_complete(ctx, current_dir)
168+ -- if next_path then
169+ -- local success, error = pcall(read_dir, next_path)
170+ -- if not success then
171+ -- log.error(next_path, ": ", error)
172+ -- end
173+ -- else
174+ -- on_exit()
175+ -- end
154176 end
155177
156- -- local next_path = dir_complete(ctx, current_dir)
157- -- if next_path then
158- -- local success, error = pcall(read_dir, next_path)
159- -- if not success then
160- -- log.error(next_path, ": ", error)
161- -- end
162- -- else
163- -- on_exit()
164- -- end
178+ uv .fs_readdir (dir , on_fs_readdir )
165179 end
166180 end
167181
168- uv .fs_scandir (current_dir , on_fs_scandir )
182+ uv .fs_opendir (current_dir , on_fs_opendir )
169183 end
170184
171185 -- local first = table.remove(context.paths_to_load)
0 commit comments