fix: preserve devicons highlight groups in nonicons icon provider

Problem: when the nonicons direct API was detected, all icons were
returned with the generic 'OilFileIcon' highlight group, losing
per-filetype colors from nvim-web-devicons.

Solution: resolve highlight groups from devicons when available so
nonicons glyphs retain their per-filetype colors.
This commit is contained in:
Barrett Ruth 2026-02-23 15:16:25 -05:00
parent c51e3168de
commit 60bfbe05da

View file

@ -947,23 +947,26 @@ M.get_icon_provider = function()
local has_nonicons, nonicons = pcall(require, 'nonicons') local has_nonicons, nonicons = pcall(require, 'nonicons')
if has_nonicons and nonicons.get_icon then if has_nonicons and nonicons.get_icon then
local _, devicons = pcall(require, 'nvim-web-devicons')
return function(type, name, conf, ft) return function(type, name, conf, ft)
if type == 'directory' then if type == 'directory' then
local icon = nonicons.get('file-directory') local icon = nonicons.get('file-directory')
return icon or (conf and conf.directory or ''), 'OilDirIcon' return icon or (conf and conf.directory or ''), 'OilDirIcon'
end end
local hl = devicons and select(2, devicons.get_icon(name)) or 'OilFileIcon'
if ft then if ft then
local ft_icon = nonicons.get_icon_by_filetype(ft) local ft_icon = nonicons.get_icon_by_filetype(ft)
if ft_icon then if ft_icon then
return ft_icon, 'OilFileIcon' local ft_hl = devicons and select(2, devicons.get_icon_by_filetype(ft))
return ft_icon, ft_hl or hl
end end
end end
local icon = nonicons.get_icon(name) local icon = nonicons.get_icon(name)
if icon then if icon then
return icon, 'OilFileIcon' return icon, hl
end end
local fallback = nonicons.get('file') local fallback = nonicons.get('file')
return fallback or (conf and conf.default_file or ''), 'OilFileIcon' return fallback or (conf and conf.default_file or ''), hl
end end
end end