From 09f749cbb1652134a6c750ef5f74f14fd3d114a2 Mon Sep 17 00:00:00 2001 From: Shadman <13149513+shadmansaleh@users.noreply.github.com> Date: Thu, 3 Mar 2022 00:37:52 +0000 Subject: [PATCH] handle cases where filetype icon highlight is not set (#589) --- lua/lualine/components/filetype.lua | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/lua/lualine/components/filetype.lua b/lua/lualine/components/filetype.lua index c1059ab..e86aa9c 100644 --- a/lua/lualine/components/filetype.lua +++ b/lua/lualine/components/filetype.lua @@ -37,19 +37,21 @@ function M:apply_icon() if icon and self.options.colored then local highlight_color = modules.utils.extract_highlight_colors(icon_highlight_group, 'fg') - local default_highlight = self:get_default_hl() - local icon_highlight = icon_hl_cache[highlight_color] - if not icon_highlight or not modules.highlight.highlight_exists(icon_highlight.name .. '_normal') then - icon_highlight = modules.highlight.create_component_highlight_group( - { fg = highlight_color }, - icon_highlight_group, - self.options, - false - ) - icon_hl_cache[highlight_color] = icon_highlight - end + if highlight_color then + local default_highlight = self:get_default_hl() + local icon_highlight = icon_hl_cache[highlight_color] + if not icon_highlight or not modules.highlight.highlight_exists(icon_highlight.name .. '_normal') then + icon_highlight = modules.highlight.create_component_highlight_group( + { fg = highlight_color }, + icon_highlight_group, + self.options, + false + ) + icon_hl_cache[highlight_color] = icon_highlight + end - icon = modules.highlight.component_format_highlight(icon_highlight) .. icon .. default_highlight + icon = modules.highlight.component_format_highlight(icon_highlight) .. icon .. default_highlight + end end else ok = vim.fn.exists('*WebDevIconsGetFileTypeSymbol')