Skip to content

Commit

Permalink
chore: use nil-guard to call iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
delphinus committed Jul 29, 2023
1 parent a18409d commit 38d12ad
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions lua/frecency/finder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,16 @@ end
---@param path string
---@return fun(prompt: string?): table[]
function Finder:create_fn(initial_results, path)
local it = self.fs:scan_dir(path)
local is_dead = false
local it = vim.F.nil_wrap(self.fs:scan_dir(path))
local results = vim.deepcopy(initial_results)
local called = 0
---@param _ string?
---@return table[]
return function(_)
if is_dead then
return results
end
called = called + 1
log:debug { called = called }
local count = 0
while true do
local ok, name = pcall(it)
if not ok then
is_dead = true
break
end
for name in it do
table.insert(results, { path = vim.fs.joinpath(path, name), score = 0 })
count = count + 1
if count >= self.config.chunk_size then
Expand Down

0 comments on commit 38d12ad

Please sign in to comment.