From 38d12ad9b75e3863212b5c07b6c5f7fdfb4b3161 Mon Sep 17 00:00:00 2001 From: delphinus Date: Sat, 29 Jul 2023 14:54:12 +0900 Subject: [PATCH] chore: use nil-guard to call iterators --- lua/frecency/finder.lua | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/lua/frecency/finder.lua b/lua/frecency/finder.lua index 58ea9199..c68e1ba8 100644 --- a/lua/frecency/finder.lua +++ b/lua/frecency/finder.lua @@ -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