Skip to content

Commit

Permalink
fix: move has_fd check into a function to reduce startup time (#390)
Browse files Browse the repository at this point in the history
* move has_fd into a function

* Make has_fd a cached function

* run stylua

---------

Co-authored-by: James Trew <j.trew10@gmail.com>
  • Loading branch information
scanhex and jamestrew authored Jun 9, 2024
1 parent 1280db1 commit a7ab9a9
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lua/telescope/_extensions/file_browser/finders.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,16 @@ local function hidden_opts(opts)
end
end

local has_fd = vim.fn.executable "fd" == 1
local has_fd_cache = nil
local has_fd = function()
if has_fd_cache == nil then
has_fd_cache = vim.fn.executable "fd" == 1
end
return has_fd_cache
end

local use_fd = function(opts)
return opts.use_fd and has_fd
return opts.use_fd and has_fd()
end

local function fd_file_args(opts)
Expand Down Expand Up @@ -206,7 +213,7 @@ fb_finders.finder = function(opts)
hidden = hidden,
depth = vim.F.if_nil(opts.depth, 1), -- depth for file browser
auto_depth = vim.F.if_nil(opts.auto_depth, false), -- depth for file browser
respect_gitignore = vim.F.if_nil(opts.respect_gitignore, has_fd),
respect_gitignore = vim.F.if_nil(opts.respect_gitignore, has_fd()),
no_ignore = vim.F.if_nil(opts.no_ignore, false),
follow_symlinks = vim.F.if_nil(opts.follow_symlinks, false),
files = vim.F.if_nil(opts.files, true), -- file or folders mode
Expand Down

0 comments on commit a7ab9a9

Please sign in to comment.