nvim-tree / nvim-web-devicons

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

fix: handle extension with multiple dots #216

Closed nobuhikosawai closed 1 year ago

nobuhikosawai commented 1 year ago

fixes: https://github.com/nvim-tree/nvim-web-devicons/issues/206

I took @gegoune's approach on this comment (https://github.com/nvim-tree/nvim-web-devicons/issues/206#issuecomment-1436045476)

Before Screenshot 2023-03-03 at 0 56 39

After Screenshot 2023-03-03 at 0 57 32

(Note that I have set the custom icon on my config for .stories.tsx )

nobuhikosawai commented 1 year ago

I've done these

alex-courtis commented 1 year ago

Looks good; I just cannot remember the original problem. I can't replicate the before/after in the description.

What's the test case? I'm trying icons_by_file_extension

  ["stories.tsx"] = {
    icon = "X",
    color = "#519aba",
    cterm_color = "74",
    name = "StoriesTsx",
  },
nobuhikosawai commented 1 year ago

Steps to reproduce

This is the minimum steps to reproduce the original problem:

  1. Set strict=true on nvim-web-devicon.
    require'nvim-web-devicons'.setup {
    strict = true,
    }
  2. Install telescope.nvim, one of the most popular fuzzy finder plugin. This plugin supports integration with nvim-web-devicons.
  3. Add foo.test.js in your project. (stories.tsx has nothing to do with reproducing the problem. Apologies for the confusion.)
  4. Search "test.js" by using :Telescope find_files.

Expected behavior: Since "test.js" is in the icons_by_file_extension table, foo.test.js should be displayed with the test.js icon. image

Actual behavior: foo.test.js appears with js icon, not test.js icon. image

You can reproduce this behavior with many other plugins (such as lualine.nvim) that support integration with nvim-web-devicons.

Please note that this is not a issue on nvim-tree because it has already been solved within the plugin itself after this PR (https://github.com/nvim-tree/nvim-tree.lua/pull/423).

My test cases

As I have written as an example in my description, I have tested the following filenames:

(This is off-topic, but maybe we should have a test code.)

Relevant issue not mentioned above.

https://github.com/nvim-tree/nvim-web-devicons/issues/36

alex-courtis commented 1 year ago
  1. Set strict=true on nvim-web-devicon.

Thank you; that seems to be the bit I was missing.

foo.test.js appears with js icon, not test.js icon.

I cannot replicate this on master. I can replicate it on your fork's master c2c2317 however the test.js and js icons are the same; test.js was updated at 87c3ded

I think I understand now:

local result = ""

local function tst(name, ext)
    local icon, hl = require('nvim-web-devicons').get_icon(name, ext, { strict = true })
    result = string.format("%s, %s (%s) %s %s", result, name, ext, icon, hl)
end

tst("test.js", "js")
tst("test.js", nil)

tst("foo.test.js", "test.js")
tst("foo.test.js", "js")
tst("foo.test.js", nil)

print(result)

master: test.js (js)  DevIconJs, test.js (nil)  DevIconJs, foo.test.js (test.js)  DevIconTestJs, foo.test.js (js)  DevIconJs, foo.test.js (nil)  DevIconJs

branch: test.js (js)  DevIconJs, test.js (nil)  DevIconJs, foo.test.js (test.js)  DevIconTestJs, foo.test.js (js)  DevIconJs, foo.test.js (nil)  DevIconTestJs

alex-courtis commented 1 year ago

(This is off-topic, but maybe we should have a test code.)

Yes, that would greatly improve quality and reduce regressions.

I'd be most grateful if you could put something together!