From 8591f3c8464dd1baaf801c5e8acf6d663c56cf6d Mon Sep 17 00:00:00 2001 From: bhagwan Date: Fri, 11 Feb 2022 23:51:54 -0800 Subject: [PATCH] oldfiles performance enhancements (#343) --- lua/fzf-lua/providers/oldfiles.lua | 34 +++++++++++++++++++----------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/lua/fzf-lua/providers/oldfiles.lua b/lua/fzf-lua/providers/oldfiles.lua index ec6724f..4254ff8 100644 --- a/lua/fzf-lua/providers/oldfiles.lua +++ b/lua/fzf-lua/providers/oldfiles.lua @@ -9,28 +9,38 @@ M.oldfiles = function(opts) local current_buffer = vim.api.nvim_get_current_buf() local current_file = vim.api.nvim_buf_get_name(current_buffer) - local results = {} + local sess_tbl = {} + local sess_map = {} if opts.include_current_session then for _, buffer in ipairs(vim.split(vim.fn.execute(':buffers! t'), "\n")) do - local match = tonumber(string.match(buffer, '%s*(%d+)')) - if match then - local file = vim.api.nvim_buf_get_name(match) - if vim.loop.fs_stat(file) and match ~= current_buffer then - table.insert(results, file) + local bufnr = tonumber(buffer:match('%s*(%d+)')) + if bufnr then + local file = vim.api.nvim_buf_get_name(bufnr) + local fs_stat = not opts.stat_file and true or vim.loop.fs_stat(file) + if #file>0 and fs_stat and bufnr ~= current_buffer then + sess_map[file] = true + table.insert(sess_tbl, file) end end end end - for _, file in ipairs(vim.v.oldfiles) do - if vim.loop.fs_stat(file) and not vim.tbl_contains(results, file) and file ~= current_file then - table.insert(results, file) + local contents = function (cb) + + local entries = {} + + for _, file in ipairs(sess_tbl) do + table.insert(entries, file) + end + for _, file in ipairs(vim.v.oldfiles) do + local fs_stat = not opts.stat_file and true or vim.loop.fs_stat(file) + if fs_stat and file ~= current_file and not sess_map[file] then + table.insert(entries, file) + end end - end - local contents = function (cb) - for _, x in ipairs(results) do + for _, x in ipairs(entries) do x = core.make_entry_file(opts, x) if x then cb(x, function(err)