Skip to content

Commit

Permalink
fix(icons): restore auto lazy-load (closes #1670)
Browse files Browse the repository at this point in the history
This commits restores lazy loading the icon package albeit with
a slight difference, the defaults now set `file_icons = 1` which
is similar to `file_icons = true` (= trigger lazy loading) without
displaying a warning message if we are unable to load the package.

This change does not affect #1663, fzf-lua will not trigger lazy
loading of the icon package when `file_icons = false`.
  • Loading branch information
ibhagwan committed Jan 5, 2025
1 parent e1eab46 commit df57ece
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
9 changes: 7 additions & 2 deletions lua/fzf-lua/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,13 @@ function M.normalize_opts(opts, globals, __resume_key)
})
then
-- Disable file_icons if requested package isn't available
utils.warn(string.format("error loading '%s', disabling 'file_icons'.",
opts.file_icons == "mini" and "mini.icons" or "nvim-web-devicons"))
-- we set the default value to "1" but since it's the default
-- don't display the warning unless the user specifically set
-- file_icons to `true` or `mini|devicons`
if not tonumber(opts.file_icons) then
utils.warn(string.format("error loading '%s', disabling 'file_icons'.",
opts.file_icons == "mini" and "mini.icons" or "nvim-web-devicons"))
end
opts.file_icons = nil
end
if opts.file_icons == "mini" then
Expand Down
41 changes: 19 additions & 22 deletions lua/fzf-lua/defaults.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
local path = require "fzf-lua.path"
local utils = require "fzf-lua.utils"
local actions = require "fzf-lua.actions"
local devicons = require "fzf-lua.devicons"
local previewers = require "fzf-lua.previewer"

local M = {}

M._has_devicons = devicons.plugin_loaded()

function M._default_previewer_fn()
local previewer = M.globals.default_previewer or M.globals.winopts.preview.default
-- the setup function cannot have a custom previewer as deepcopy
Expand Down Expand Up @@ -332,7 +329,7 @@ M.defaults.files = {
prompt = "> ",
cmd = nil, -- default: auto detect find|fd
multiprocess = true,
file_icons = true and M._has_devicons,
file_icons = 1,
color_icons = true,
git_icons = true,
cwd_prompt = true,
Expand Down Expand Up @@ -360,7 +357,7 @@ M.defaults.git = {
prompt = "GitFiles> ",
cmd = "git ls-files --exclude-standard",
multiprocess = true,
file_icons = true and M._has_devicons,
file_icons = 1,
color_icons = true,
git_icons = true,
fzf_opts = { ["--multi"] = true },
Expand All @@ -375,7 +372,7 @@ M.defaults.git = {
cmd = "git -c color.status=false --no-optional-locks status --porcelain=v1 -u",
previewer = "git_diff",
multiprocess = true,
file_icons = true and M._has_devicons,
file_icons = 1,
color_icons = true,
git_icons = true,
fzf_opts = { ["--multi"] = true },
Expand Down Expand Up @@ -497,7 +494,7 @@ M.defaults.grep = {
input_prompt = "Grep For> ",
cmd = nil, -- default: auto detect rg|grep
multiprocess = true,
file_icons = true and M._has_devicons,
file_icons = 1,
color_icons = true,
git_icons = false,
fzf_opts = { ["--multi"] = true },
Expand Down Expand Up @@ -531,7 +528,7 @@ M.defaults.args = {
previewer = M._default_previewer_fn,
prompt = "Args> ",
files_only = true,
file_icons = true and M._has_devicons,
file_icons = 1,
color_icons = true,
git_icons = true,
fzf_opts = { ["--multi"] = true },
Expand All @@ -543,7 +540,7 @@ M.defaults.args = {
M.defaults.oldfiles = {
previewer = M._default_previewer_fn,
prompt = "History> ",
file_icons = true and M._has_devicons,
file_icons = 1,
color_icons = true,
git_icons = false,
stat_file = true,
Expand All @@ -556,7 +553,7 @@ M.defaults.quickfix = {
previewer = M._default_previewer_fn,
prompt = "Quickfix> ",
separator = "",
file_icons = true and M._has_devicons,
file_icons = 1,
color_icons = true,
git_icons = false,
fzf_opts = { ["--multi"] = true },
Expand All @@ -578,7 +575,7 @@ M.defaults.loclist = {
previewer = M._default_previewer_fn,
prompt = "Locations> ",
separator = "",
file_icons = true and M._has_devicons,
file_icons = 1,
color_icons = true,
git_icons = false,
fzf_opts = { ["--multi"] = true },
Expand All @@ -599,7 +596,7 @@ M.defaults.loclist_stack = {
M.defaults.buffers = {
previewer = M._default_previewer_fn,
prompt = "Buffers> ",
file_icons = true and M._has_devicons,
file_icons = 1,
color_icons = true,
sort_lastused = true,
show_unloaded = true,
Expand All @@ -620,7 +617,7 @@ M.defaults.tabs = {
prompt = "Tabs> ",
tab_title = "Tab",
tab_marker = "<<",
file_icons = true and M._has_devicons,
file_icons = 1,
color_icons = true,
_actions = function()
return M.globals.actions.buffers or M.globals.actions.files
Expand All @@ -640,7 +637,7 @@ M.defaults.tabs = {
M.defaults.lines = {
previewer = M._default_previewer_fn,
prompt = "Lines> ",
file_icons = true and M._has_devicons,
file_icons = 1,
color_icons = true,
show_bufname = 120,
show_unloaded = true,
Expand Down Expand Up @@ -719,7 +716,7 @@ M.defaults.tags = {
rg_opts = "--no-heading --color=always --smart-case",
grep_opts = "--color=auto --perl-regexp",
multiprocess = true,
file_icons = true and M._has_devicons,
file_icons = 1,
git_icons = false,
color_icons = true,
fzf_opts = {
Expand Down Expand Up @@ -828,7 +825,7 @@ M.defaults.manpages = {
M.defaults.lsp = {
previewer = M._default_previewer_fn,
prompt_postfix = "> ",
file_icons = true and M._has_devicons,
file_icons = 1,
color_icons = true,
git_icons = false,
async_or_timeout = 5000,
Expand All @@ -843,7 +840,7 @@ M.defaults.lsp = {
M.defaults.lsp.symbols = {
previewer = M._default_previewer_fn,
prompt_postfix = "> ",
file_icons = true and M._has_devicons,
file_icons = 1,
color_icons = true,
git_icons = false,
symbol_style = 1,
Expand Down Expand Up @@ -915,7 +912,7 @@ M.defaults.lsp.symbols = {
M.defaults.lsp.finder = {
previewer = M._default_previewer_fn,
prompt = "LSP Finder> ",
file_icons = true and M._has_devicons,
file_icons = 1,
color_icons = true,
git_icons = false,
async = true,
Expand Down Expand Up @@ -963,7 +960,7 @@ M.defaults.lsp.code_actions = {
M.defaults.diagnostics = {
previewer = M._default_previewer_fn,
prompt = "Diagnostics> ",
file_icons = true and M._has_devicons,
file_icons = 1,
color_icons = true,
git_icons = false,
diag_icons = true,
Expand Down Expand Up @@ -1025,7 +1022,7 @@ M.defaults.jumps = {

M.defaults.tagstack = {
prompt = "Tagstack> ",
file_icons = true and M._has_devicons,
file_icons = 1,
color_icons = true,
git_icons = true,
fzf_opts = { ["--multi"] = true },
Expand Down Expand Up @@ -1155,7 +1152,7 @@ M.defaults.dap = {
},
breakpoints = {
prompt = "DAP Breakpoints> ",
file_icons = true and M._has_devicons,
file_icons = 1,
color_icons = true,
git_icons = false,
previewer = M._default_previewer_fn,
Expand Down Expand Up @@ -1183,7 +1180,7 @@ M.defaults.complete_path = {
M.defaults.complete_file = {
cmd = nil, -- default: auto detect rg|fd|find
multiprocess = true,
file_icons = true and M._has_devicons,
file_icons = 1,
color_icons = true,
git_icons = false,
_actions = function() return M.globals.actions.files end,
Expand Down

0 comments on commit df57ece

Please sign in to comment.