Closed carljohnson93 closed 1 year ago
Problem: complete filename or extension is matched by nvim-tree.
Possible solution: nvim-tree matches by extension only.
nvim-web-devicons is capable of "extension only" by passing a nil name
to get_icon
.
That could be done here: https://github.com/nvim-tree/nvim-tree.lua/blob/dcc344cc72a617ff01db950aedfd3b3430ba5b59/lua/nvim-tree/renderer/components/icons.lua#L45
I may be oversimplifying this.
Okay, but, the thing is, nvim-tree is not the only plugin using nvim-web-devicons, and I for example have custom components and extensions for lualine which use get_icon
too and have the same problem.
If the proposed change (again, it is completely non-breaking) is not welcome, I'll just use my fork and be happy - just say so, because I have uncommited changes to my init.lua for a week now 😅 and I just want to move on
Wait, I just actually thought about what you said and now I'm thinking am I actually this darn stupid? I will try what you suggested
Whew, thanks god it's not that simple actually. Basically now filename-based icons will not show up because we don't pass filename, plus by passing filename with extension as the first argument, and just extension as a second argument to get_icon
allows to have really specific icon just for that specific filename, even with extension (I'm not talking about nvim-tree now but generally about usage of get_icon
). So question before my previous comment still holds.
Whew, thanks god it's not that simple actually. Basically now filename-based icons will not show up because we don't pass filename, plus by passing filename with extension as the first argument, and just extension as a second argument to
get_icon
allows to have really specific icon just for that specific filename, even with extension (I'm not talking about nvim-tree now but generally about usage ofget_icon
). So question before my previous comment still holds.
That makes sense; it's a well used case.
How about you put together a PR:
opts.strict
if possible
So I've been using NvimTree (which as you know uses nvim-web-devicons) for the past few weeks, and noticed something that seemed not very "as-intended" to me. So as far as I understood by looking at implementation basically nvim-web-devicons has one table and both icons for filenames and icons for file extensions reside there. This results in various icons being displayed for files which happen to have a name that matches the extension in this table, example:
I've played around with code a bit and came up with completely backward-compatible solution that fixed that problem; example:
As you can see now files that do not have extension have a default icon, as I would personally expect. Basically here's what I changed:
icons_by_filename
,icons_by_file_extension
andicons
strict
(didn't came up with a better name yet) which is false by default but when true -get_icon
looks upicons_by_filename
for icon byname
, andicons_by_file_extension
for icon byext
override.by_filename
andoverride.by_extension
Icons from both tables are still "merged" into
icons
table and user can still provide icons for both filenames and extensions inoverride
, so this feature is completely backward compatible.What do you think? Should I do a PR or should I just keep my fork and use it?