Skip to content

Commit

Permalink
feat: do not lazy load icon package on init (#1663)
Browse files Browse the repository at this point in the history
Will still lazy load when called with `file_icons = true` or
`file_icons = "mini"` as prior to this commit.
  • Loading branch information
ibhagwan committed Jan 2, 2025
1 parent b622a44 commit 116170c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
28 changes: 18 additions & 10 deletions lua/fzf-lua/devicons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ function NvimWebDevicons:new()
return self
end

function NvimWebDevicons:load()
function NvimWebDevicons:load(do_not_lazy_load)
-- limit devicons support to nvim >=0.8, although official support is >=0.7
-- running setup on 0.7 errs with "W18: Invalid character in group name"
if not self._package_loaded and utils.__HAS_NVIM_07 then
if not self._package_loaded and utils.__HAS_NVIM_07
-- do not trigger lazy loading
and (not do_not_lazy_load or package.loaded[self._package_name])
then
self._package_loaded, self._package = pcall(require, self._package_name)
if self._package_loaded then
self._package_path = path.parent(path.parent(path.normalize(
Expand Down Expand Up @@ -176,8 +179,11 @@ function MiniIcons:new()
return self
end

function MiniIcons:load()
if not self._package_loaded and utils.__HAS_NVIM_08 then
function MiniIcons:load(do_not_lazy_load)
if not self._package_loaded and utils.__HAS_NVIM_08
-- do not trigger lazy loading
and (not do_not_lazy_load or package.loaded[self._package_name])
then
self._package_loaded, self._package = pcall(require, self._package_name)
if self._package_loaded then
self._package_path = path.parent(path.parent(path.parent(path.normalize(
Expand Down Expand Up @@ -292,7 +298,7 @@ function FzfLuaServer:path()
return _G._fzf_lua_server or vim.g.fzf_lua_server
end

function FzfLuaServer:load()
function FzfLuaServer:load(_)
return type(self:path()) == "string"
end

Expand Down Expand Up @@ -344,7 +350,7 @@ M.__DEVICONS = NvimWebDevicons:new()
-- "auto" prefers nvim-web-devicons, "srv" RPC-queries main instance
---@param provider boolean|string|"auto"|"devicons"|"mini"|"srv"
---@return boolean success
M.plugin_load = function(provider)
M.plugin_load = function(provider, do_not_lazy_load)
-- Called from "make_entry.lua" without params (already loaded)
if provider == nil and M.PLUGIN and M.PLUGIN:loaded() then
return true
Expand Down Expand Up @@ -379,7 +385,8 @@ M.plugin_load = function(provider)
-- Load mini only if `_G.MiniIcons` is present or if using `mock_nvim_web_devicons()`
-- at which point we would like to replace the mock with first-class MiniIcons (#1358)
---@diagnostic disable-next-line: undefined-field
if not M.__DEVICONS:load() and _G.MiniIcons or M.__DEVICONS:is_mock() and M.__MINI:load()
if not M.__DEVICONS:load(do_not_lazy_load) and _G.MiniIcons
or M.__DEVICONS:is_mock() and M.__MINI:load(do_not_lazy_load)
then
ret = M.__MINI
end
Expand All @@ -393,11 +400,12 @@ M.plugin_load = function(provider)
end
return ret
end)()
return M.PLUGIN:load()
return M.PLUGIN:load(do_not_lazy_load)
end

-- Attemp to loadeLoa icons plugin at least once on require
M.plugin_load()
-- Attempt to load icons plugin at least once on init but
-- do not use `require` so we do not lazy load the plugin
M.plugin_load(nil, true)

M.plugin_loaded = function()
return M.PLUGIN:loaded()
Expand Down
1 change: 1 addition & 0 deletions scripts/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ vim.cmd("set packpath=" .. packpath)

vim.o.termguicolors = true

pcall(require, "nvim-web-devicons")
require "fzf-lua".setup { defaults = { git_icons = false } }

vim.api.nvim_set_keymap("n", "<C-\\>", [[<Cmd>lua require"fzf-lua".buffers()<CR>]], {})
Expand Down

0 comments on commit 116170c

Please sign in to comment.