Skip to content

Commit 385f8c8

Browse files
authored
feat: show default file icon when nvim-devicon is not installed (#696)
1 parent c0dcbbd commit 385f8c8

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

lua/nvim-tree/colors.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ local function get_links()
7979
end
8080

8181
function M.setup()
82-
if config.get_icon_state().show_file_icon then
82+
if config.get_icon_state().show_file_icon and config.get_icon_state().has_devicons then
8383
require'nvim-web-devicons'.setup()
8484
end
8585
local higlight_groups = get_hl_groups()

lua/nvim-tree/config.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ function M.get_icon_state()
6060

6161
local has_devicons = pcall(require, 'nvim-web-devicons')
6262
return {
63-
show_file_icon = show_icons.files == 1 and has_devicons,
63+
show_file_icon = show_icons.files == 1,
6464
show_folder_icon = show_icons.folders == 1,
6565
show_git_icon = show_icons.git == 1,
6666
show_folder_arrows = show_icons.folder_arrows == 1,
67+
has_devicons = has_devicons,
6768
icons = icons
6869
}
6970
end

lua/nvim-tree/renderer/init.lua

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,29 @@ end
5656

5757
local get_file_icon = function() return "" end
5858
if icon_state.show_file_icon then
59-
local web_devicons = require'nvim-web-devicons'
59+
if icon_state.has_devicons then
60+
local web_devicons = require'nvim-web-devicons'
6061

61-
get_file_icon = function(fname, extension, line, depth)
62-
local icon, hl_group = web_devicons.get_icon(fname, extension)
62+
get_file_icon = function(fname, extension, line, depth)
63+
local icon, hl_group = web_devicons.get_icon(fname, extension)
6364

64-
if icon and hl_group ~= "DevIconDefault" then
65-
if hl_group then
66-
table.insert(hl, { hl_group, line, depth, depth + #icon + 1 })
65+
if icon and hl_group ~= "DevIconDefault" then
66+
if hl_group then
67+
table.insert(hl, { hl_group, line, depth, depth + #icon + 1 })
68+
end
69+
return icon..icon_padding
70+
elseif string.match(extension, "%.(.*)") then
71+
-- If there are more extensions to the file, try to grab the icon for them recursively
72+
return get_file_icon(fname, string.match(extension, "%.(.*)"), line, depth)
73+
else
74+
return #icon_state.icons.default > 0 and icon_state.icons.default..icon_padding or ""
6775
end
68-
return icon..icon_padding
69-
elseif string.match(extension, "%.(.*)") then
70-
-- If there are more extensions to the file, try to grab the icon for them recursively
71-
return get_file_icon(fname, string.match(extension, "%.(.*)"), line, depth)
72-
else
76+
end
77+
else
78+
get_file_icon = function()
7379
return #icon_state.icons.default > 0 and icon_state.icons.default..icon_padding or ""
7480
end
7581
end
76-
7782
end
7883

7984
local get_symlink_icon = function() return icon_state.icons.symlink end

0 commit comments

Comments
 (0)