From c76d6d9b36e2b0bbee70ad3d20d0047dd07a12b1 Mon Sep 17 00:00:00 2001 From: bhagwan Date: Fri, 23 Jul 2021 11:10:22 -0700 Subject: [PATCH] nvim-web-devicons lazy load bugfix --- lua/fzf-lua/config.lua | 10 +++++++++- lua/fzf-lua/core.lua | 6 +++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lua/fzf-lua/config.lua b/lua/fzf-lua/config.lua index 7cda1c6..f76458a 100644 --- a/lua/fzf-lua/config.lua +++ b/lua/fzf-lua/config.lua @@ -8,7 +8,15 @@ local actions = require "fzf-lua.actions" local M = {} -M._has_devicons = pcall(require, "nvim-web-devicons") +M._has_devicons, M._devicons = pcall(require, "nvim-web-devicons") + +-- if the caller has devicons lazy loaded +-- this will generate an error +-- nvim-web-devicons.lua:972: E5560: +-- nvim_command must not be called in a lua loop callback +if M._has_devicons and not M._devicons.has_loaded() then + M._devicons.setup() +end M.win_height = 0.85 M.win_width = 0.80 diff --git a/lua/fzf-lua/core.lua b/lua/fzf-lua/core.lua index 6d5cffe..e56b520 100644 --- a/lua/fzf-lua/core.lua +++ b/lua/fzf-lua/core.lua @@ -8,9 +8,9 @@ local M = {} M.get_devicon = function(file, ext) local icon = '' - if not file or #file == 0 then return icon end - if config._has_devicons then - local devicon = require'nvim-web-devicons'.get_icon(file, ext) + if not file or #file == 0 then return icon end + if config._has_devicons and config._devicons then + local devicon = config._devicons.get_icon(file, ext) if devicon then icon = devicon end end return icon