bufferline.nvim
bufferline.nvim copied to clipboard
[Bug]: Bufferline don't show overidden icons which are set by nvim-web-devicons
What happened?
local devicons = require('nvim-web-devicons')
local override = {
["spec.ts"] = {
icon = "",
color = "#ffc600",
name = "TsTest",
},
}
devicons.setup {
override = override,
default = true,
}
What did you expect to happen?
-- Test config
print(vim.inspect(devicons.get_icon('test.component.spec.ts'))) -- print:
Additional Information
commit
No response
Hi @CaptainKO, can you confirm when you are setting this override i.e. are you sure it is being set before bufferline starts?
Hi @akinsho.
I put it right in the config callback.
As I can see right now nvim-tree
and coc-explorer
are working fine.
use {
"kyazdani42/nvim-web-devicons",
config = function()
local override = {
["spec.ts"] = {
icon = "",
color = "#ffc600",
name = "TsTest",
},
}
require("nvim-web-devicons").setup {
-- your personnal icons can go here (to override)
-- DevIcon will be appended to `name`
-- override = vim.tbl_extend("keep",override ,devicons.get_icons()),
override = override,
-- globally enable default icons (default to false)
-- will get overriden by `get_icons` option
default = true,
}
end,
}
@CaptainKO sorry I should have clarified, does bufferline load before nvim-web-devicons
or not? i.e. if you are applying the override after bufferline has already loaded, then that might be why you don't see them applied
I've also made a few changes to how icons are required. Can you test it out and see if it works now
Thank you. I will check it out ASAP.
Unfortunately, nothing changes.
I have updated to the latest version and made sure that the nvim-web-devicons
was configured before loading bufferline
.
-- ...
use {
"akinsho/bufferline.nvim",
requires = "kyazdani42/nvim-web-devicons",
config = config "bufferline",
after = { "nvim-web-devicons" },
}
-- ...
Actually bufferline
properly shows the overridden icon if the icon was specified only by the extension.
local override = {
["spec.ts"] = { -- not working
icon = "",
color = "#ffc600",
name = "TsTest",
},
["snippets"] = { -- works fine
icon = " ",
color = "#ffc600",
name = "Snippet",
},
}
I did open an issue on the coc-explorer
repo. They simply fixed this by passing the full filename - commit
@CaptainKO thanks for the reference to the commit in coc-explorer 👍🏿 . I tried locally passing the full file name to the get icon method but that didn't work. It did however work when I passed in the full extension i.e. spec.ts
by default bufferline will only pass .ts
to devicons
Actually I've dug into this a lot more and actually checked the code of nvim-tree where this is also used, and I think maybe that this is an upstream problem or should be partially resolved upstream. Basically devicons maintains a map of file extensions/names and does a direct lookup e.g. table[extension] = icon
so in this case I wasn't passing the full spec.ts
so it doesn't match your override. The problem with passing in the full extension as spec.js
or something is that these filetypes aren't available by default, so passing that extension will break for all other users.
Nvim tree does some recursive logic and some attempt to check against a highlight group to continue testing the extension for a match. I could implement similar logic here, but I don't think that all consumers of the plugin should have to do this kind of recursive extension matching. I think it would be better if nvim-devicons offered the ability to pass the full extension, and it tried to match as much as it could. It would work better internally implemented as well because with the plugin it could check for actually matches/misses by checking the icon object directly which doesn't work in the case of default = true
.
@kyazdani42 thoughts? (pinging you re. whether or not you think this logic should be internal in devicons).
ref: https://github.com/kyazdani42/nvim-tree.lua/blob/e741680edb0524f601a91d65ef90a0af0915a0c3/lua/nvim-tree/renderer.lua#L56
Implementation idea:
setmetatable(icons, {
__index = function(t, key)
if key:match(".") then -- or a better regex
-- recursively truncate the key and see if the smaller extension matches
end
end
})
I guess it could work, and it might actually be more efficient than custom implementations.
Hi @akinsho @kyazdani42, first of all thanks for this wonderful plugins, i was wondering if there is any progress into this issue?
With this config in devicons.lua
override_by_extension = { ["angular.json"] = { icon = "", color = '#f38ba8', name = 'AngularJson' }, },
@jgarciaokode nope no progress, this isn't something that affects me much in my daily life and I haven't the time to look into it, but as with all issues on this repo, contributions are very welcome