nvim-tree / nvim-web-devicons

lua `fork` of vim-web-devicons for neovim
MIT License
2k stars 182 forks source link

Feature proposal (ready to do a PR): distinguish between filename-based icons and file extension-based icons #194

Closed carljohnson93 closed 1 year ago

carljohnson93 commented 1 year ago

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:

Screen Shot 2023-01-31 at 8 27 20 AM

I've played around with code a bit and came up with completely backward-compatible solution that fixed that problem; example:

Screen Shot 2023-01-31 at 8 28 32 AM

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 from both tables are still "merged" into icons table and user can still provide icons for both filenames and extensions in override, 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?

alex-courtis commented 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.

carljohnson93 commented 1 year ago

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

carljohnson93 commented 1 year ago

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

carljohnson93 commented 1 year ago

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.

alex-courtis commented 1 year ago

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.

That makes sense; it's a well used case.

How about you put together a PR: