Skip to content

Commit b64f2c6

Browse files
committed
Fix formatting
1 parent e889d06 commit b64f2c6

File tree

1 file changed

+69
-80
lines changed

1 file changed

+69
-80
lines changed

lua/neo-tree/sources/filesystem/lib/fs_scan.lua

Lines changed: 69 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ local dir_complete = function(context, dir_path)
7373
end
7474

7575
local job_complete = function(context)
76+
print("ASYNC JOB COMPLETE!!!")
7677
local state = context.state
7778
local root = context.root
7879
local parent_id = context.parent_id
@@ -130,35 +131,28 @@ local function get_children_sync(path)
130131
if success2 and stats then
131132
for _, stat in ipairs(stats) do
132133
local child_path = utils.path_join(path, stat.name)
133-
table.insert(children, { path = child_path, type = stat.type})
134+
table.insert(children, { path = child_path, type = stat.type })
134135
end
135136
end
136137
vim.loop.fs_closedir(dir)
137138
return children
138139
end
139140

140141
local function get_children_async(path, callback)
141-
uv.fs_opendir(
142-
path,
143-
function(_, dir)
144-
print("Async cb of: " .. path)
145-
uv.fs_readdir(
146-
dir,
147-
function(_, stats)
148-
local children = {}
149-
if stats then
150-
for _, stat in ipairs(stats) do
151-
local child_path = utils.path_join(path, stat.name)
152-
table.insert(children, { path = child_path, type = stat.type})
153-
end
154-
end
155-
uv.fs_closedir(dir)
156-
callback(children)
142+
uv.fs_opendir(path, function(_, dir)
143+
print("Async cb of: " .. path)
144+
uv.fs_readdir(dir, function(_, stats)
145+
local children = {}
146+
if stats then
147+
for _, stat in ipairs(stats) do
148+
local child_path = utils.path_join(path, stat.name)
149+
table.insert(children, { path = child_path, type = stat.type })
157150
end
158-
)
159-
end,
160-
1000
161-
)
151+
end
152+
uv.fs_closedir(dir)
153+
callback(children)
154+
end)
155+
end, 1000)
162156
end
163157

164158
local function scan_dir_sync(context, path)
@@ -207,20 +201,17 @@ local function async_scan(context, path)
207201
if scan_mode == "deep" then
208202
local scan_tasks = {}
209203
for _, p in ipairs(context.paths_to_load) do
210-
local scan_task = async.wrap(
211-
function(callback)
204+
local scan_task = async.wrap(function(callback)
212205
scan_dir_async(context, p, callback)
213-
end,
214-
1
215-
)
206+
end, 1)
216207
table.insert(scan_tasks, scan_task)
217208
end
218209

219210
async.util.run_all(
220-
scan_tasks,
221-
vim.schedule_wrap(function ()
222-
job_complete(context)
223-
end)
211+
scan_tasks,
212+
vim.schedule_wrap(function()
213+
job_complete(context)
214+
end)
224215
)
225216
else -- scan_mode == "shallow"
226217
-- prepend the root path
@@ -230,64 +221,63 @@ local function async_scan(context, path)
230221
context.directories_to_scan = #context.paths_to_load
231222

232223
context.on_exit = vim.schedule_wrap(function()
233-
job_complete(context)
234-
end)
224+
job_complete(context)
225+
end)
235226

236-
-- from https://github.com/nvim-lua/plenary.nvim/blob/master/lua/plenary/scandir.lua
237-
local function read_dir(current_dir, ctx)
238-
local on_fs_scandir = function(err, fd)
239-
if err then
240-
log.error(current_dir, ": ", err)
241-
else
242-
while true do
243-
local name, typ = uv.fs_scandir_next(fd)
244-
if name == nil then
245-
break
246-
end
247-
local entry = utils.path_join(current_dir, name)
248-
local success, item = pcall(file_items.create_item, ctx, entry, typ)
249-
if success then
250-
if ctx.recursive and item.type == "directory" then
251-
ctx.directories_to_scan = ctx.directories_to_scan + 1
252-
table.insert(ctx.paths_to_load, item.path)
253-
end
254-
else
255-
log.error("error creating item for ", path)
256-
end
257-
end
258-
on_directory_loaded(ctx, current_dir)
259-
ctx.directories_scanned = ctx.directories_scanned + 1
260-
if ctx.directories_scanned == #ctx.paths_to_load then
261-
ctx.on_exit()
262-
end
263-
264-
--local next_path = dir_complete(ctx, current_dir)
265-
--if next_path then
266-
-- local success, error = pcall(read_dir, next_path)
267-
-- if not success then
268-
-- log.error(next_path, ": ", error)
269-
-- end
270-
--else
271-
-- on_exit()
272-
--end
227+
-- from https://github.com/nvim-lua/plenary.nvim/blob/master/lua/plenary/scandir.lua
228+
local function read_dir(current_dir, ctx)
229+
local on_fs_scandir = function(err, fd)
230+
if err then
231+
log.error(current_dir, ": ", err)
232+
else
233+
while true do
234+
local name, typ = uv.fs_scandir_next(fd)
235+
if name == nil then
236+
break
237+
end
238+
local entry = utils.path_join(current_dir, name)
239+
local success, item = pcall(file_items.create_item, ctx, entry, typ)
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)
273244
end
245+
else
246+
log.error("error creating item for ", path)
274247
end
275-
276-
uv.fs_scandir(current_dir, on_fs_scandir)
248+
end
249+
on_directory_loaded(ctx, current_dir)
250+
ctx.directories_scanned = ctx.directories_scanned + 1
251+
if ctx.directories_scanned == #ctx.paths_to_load then
252+
ctx.on_exit()
277253
end
278254

279-
--local first = table.remove(context.paths_to_load)
280-
--local success, err = pcall(read_dir, first)
281-
--if not success then
282-
-- log.error(first, ": ", err)
255+
--local next_path = dir_complete(ctx, current_dir)
256+
--if next_path then
257+
-- local success, error = pcall(read_dir, next_path)
258+
-- if not success then
259+
-- log.error(next_path, ": ", error)
260+
-- end
261+
--else
262+
-- on_exit()
283263
--end
284-
for i = 1, context.directories_to_scan do
285-
read_dir(context.paths_to_load[i], context)
286-
end
264+
end
265+
end
266+
267+
uv.fs_scandir(current_dir, on_fs_scandir)
268+
end
269+
270+
--local first = table.remove(context.paths_to_load)
271+
--local success, err = pcall(read_dir, first)
272+
--if not success then
273+
-- log.error(first, ": ", err)
274+
--end
275+
for i = 1, context.directories_to_scan do
276+
read_dir(context.paths_to_load[i], context)
277+
end
287278
end
288279
end
289280

290-
291281
local function sync_scan(context, path_to_scan)
292282
log.trace("sync_scan: ", path_to_scan)
293283
local scan_mode = require("neo-tree").config.filesystem.scan_mode
@@ -324,7 +314,6 @@ local function sync_scan(context, path_to_scan)
324314
else
325315
job_complete(context)
326316
end
327-
328317
end
329318
end
330319

0 commit comments

Comments
 (0)