@@ -108,15 +108,15 @@ local function async_scan(context, path)
108108 -- prepend the root path
109109 table.insert (context .paths_to_load , 1 , path )
110110
111- local directories_scanned = 0
112- local directories_to_scan = # context .paths_to_load
111+ context . directories_scanned = 0
112+ context . directories_to_scan = # context .paths_to_load
113113
114- local on_exit = vim .schedule_wrap (function ()
114+ context . on_exit = vim .schedule_wrap (function ()
115115 job_complete (context )
116116 end )
117117
118118 -- from https://github.com/nvim-lua/plenary.nvim/blob/master/lua/plenary/scandir.lua
119- local function read_dir (current_dir )
119+ local function read_dir (current_dir , ctx )
120120 local on_fs_scandir = function (err , fd )
121121 if err then
122122 log .error (current_dir , " : " , err )
@@ -127,23 +127,23 @@ local function async_scan(context, path)
127127 break
128128 end
129129 local entry = current_dir .. os_sep .. name
130- local success , item = pcall (file_items .create_item , context , entry , typ )
130+ local success , item = pcall (file_items .create_item , ctx , entry , typ )
131131 if success then
132- if context .recursive and item .type == " directory" then
133- directories_to_scan = directories_to_scan + 1
134- read_dir ( item .path )
132+ if ctx .recursive and item .type == " directory" then
133+ ctx . directories_to_scan = ctx . directories_to_scan + 1
134+ table.insert ( ctx . paths_to_load , item .path )
135135 end
136136 else
137137 log .error (" error creating item for " , path )
138138 end
139139 end
140- on_directory_loaded (context , current_dir )
141- directories_scanned = directories_scanned + 1
142- if directories_scanned == # context .paths_to_load then
143- on_exit ()
140+ on_directory_loaded (ctx , current_dir )
141+ ctx . directories_scanned = ctx . directories_scanned + 1
142+ if ctx . directories_scanned == # ctx .paths_to_load then
143+ ctx . on_exit ()
144144 end
145145
146- -- local next_path = dir_complete(context , current_dir)
146+ -- local next_path = dir_complete(ctx , current_dir)
147147 -- if next_path then
148148 -- local success, error = pcall(read_dir, next_path)
149149 -- if not success then
@@ -163,8 +163,8 @@ local function async_scan(context, path)
163163 -- if not success then
164164 -- log.error(first, ": ", err)
165165 -- end
166- for i = 1 , directories_to_scan do
167- read_dir (context .paths_to_load [i ])
166+ for i = 1 , context . directories_to_scan do
167+ read_dir (context .paths_to_load [i ], context )
168168 end
169169end
170170
0 commit comments