Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: is intended behavior to return custom icon only on exact match? #84

Closed
saviocmc opened this issue Sep 27, 2021 · 7 comments
Closed

Comments

@saviocmc
Copy link

There are some file names that have special icons, different for the icon related to the file extension.
Example: the .gitlab-ci.yml has its own icon, which is different from the icon for other .yml files.

That's great! But the custom icon is only returned if I call the get_icon function with the exact filename. If the special file is under another path, the default icon is returned:
If call :lua print(require('nvim-web-devicons').get_icon('.gitlab-ci.yml')) I get the special gitlab icon. (Great!)
But if I call :lua print(require('nvim-web-devicons').get_icon('otherdir/.gitlab-ci.yml')) I get default .yml icon.

The same happens if I define some special icon by myself, like package.json or .eslintrc.js.

This can be resolved by using the function vim.fn.fnamemodify with the flag ':t' to provide get_icon only the tail of the file path.

I would like to know if this is the intended behavior. If it is, I think a tip could be added to the README instructing the user about using vim.fn.fnamemodify to not miss the special icons.

I notice that using telescope.nvim. With the fuzzy finder, the special icons are rendered only if the file is in the vim current directory, otherwise the 'defaults' icons are displayed. I just want to check with you before submitting a PR to telescope about using vim.fn.fnamemodify to avoid this inconsistency.

@kyazdani42
Copy link
Member

This was intended behavior. I wrote this plugin to solve performance issues in my tree regarding vim-devicons, but my tree only needs to pass the filename as it is so it does not really matter to me.
Thing is, the more we add more logic inside this plugin, the slower it'll get for every user of the library. A note in the readme might be more appropriate, although i'm not sure the performance implications would be tremendous adding some parsing logic on the pathnames. I think i would accept a PR :)

@gegoune
Copy link
Collaborator

gegoune commented Feb 14, 2023

@saviocmc Do you know if your solution was adopted by Telescope team?

@saviocmc
Copy link
Author

@gegoune Yes, it was! Telescope now uses only the file name (not the complete file path, as before) to call this plugins, this way the icons are always consistent. This issue can be closed. Sorry for the delay, appreciate your work.

@saviocmc
Copy link
Author

For future reference, here is the helper function that seems to do the trick:

https://github.com/nvim-telescope/telescope.nvim/blob/a3f17d3baf70df58b9d3544ea30abe52a7a832c2/lua/telescope/utils.lua#L175

Perhaps it could be added to this plugin as an input sanitization step if it proves not to be a significant performance hit.

@gegoune
Copy link
Collaborator

gegoune commented Feb 27, 2023

That's is a good news, thank you for getting back to us!

@gegoune
Copy link
Collaborator

gegoune commented Feb 27, 2023

@alex-courtis Wouldn't #84 (comment) solve regex issues?

@alex-courtis
Copy link
Member

@alex-courtis Wouldn't #84 (comment) solve regex issues?

We could add an option like the very recently added strict https://github.com/nvim-tree/nvim-web-devicons#get-icon

I'm very hesitant to make any changes that might break existing behaviour, as the blast radius for this plugin is very large.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants