ibhagwan / fzf-lua

Improved fzf.vim written in lua
MIT License
2.34k stars 151 forks source link

Can not get correct devicons #668

Closed sandangel closed 1 year ago

sandangel commented 1 year ago

Info

I got this error after the latest update. I already reinstall the plugin but still same error

"/nix-config/users/sand/nvim/lua/plugins/lspconfig.lua" 176L, 5553B
E5108: Error executing lua: ...hare/nvim/lazy/fzf-lua/lua/fzf-lua/providers/buffers.lua:253: attempt to call a nil value
stack traceback:
    ...hare/nvim/lazy/fzf-lua/lua/fzf-lua/providers/buffers.lua:253: in function 'buffer_lines'
    ...hare/nvim/lazy/fzf-lua/lua/fzf-lua/providers/buffers.lua:223: in function 'blines'
    /home/sand/.config/nvim/lua/plugins/fzf.lua:113: in function </home/sand/.config/nvim/lua/plugins/fzf.lua:113>
fzf-lua configuration ```lua require('fzf-lua').setup({ keymap = { builtin = { [''] = 'toggle-help', [''] = 'toggle-fullscreen', [''] = 'toggle-preview', [''] = 'preview-page-down', [''] = 'preview-page-up', [''] = 'preview-page-reset', }, fzf = { ['tab'] = 'toggle', ['ctrl-a'] = 'toggle-all', ['ctrl-f'] = 'half-page-down', ['ctrl-b'] = 'half-page-up', }, }, fzf_opts = { ['--layout'] = false, ['--history'] = fzf_history_dir .. '/fzf-lua', ['--history-size'] = '2000', }, actions = { files = { ['ctrl-s'] = fzf_lua.actions.file_vsplit, }, buffers = { ['ctrl-s'] = fzf_lua.actions.buf_vsplit, } }, grep = { git_icons = false, file_icons = false, color_icons = false, }, oldfiles = { cwd_only = true, include_current_session = true, }, }) ```

Description

ibhagwan commented 1 year ago

This seems to be coming from the devicons integration, does files or anything else works normally?

Does :FzfLua blines color_icons=false works?

sandangel commented 1 year ago

@ibhagwan files and grep work fine. :FzfLua blines color_icons=false also work

ibhagwan commented 1 year ago

A few more questions:

sandangel commented 1 year ago
nil
ibhagwan commented 1 year ago

Does lines|blines work with mini.sh (wasn't clear to me if you tested from the OP)?

You didn't answer this, can you try running sh -c "$(curl -s https://raw.githubusercontent.com/ibhagwan/fzf-lua/main/scripts/mini.sh)" and tell me if it works?

There's an issue setting up devicon highlights, I'm surprised files is working for you given there's no file_icons=false under your setup.files.

More questions:

sandangel commented 1 year ago

I think I messed up my icons config

sandangel commented 1 year ago

thanks a lot for helping

ibhagwan commented 1 year ago

https://github.com/ibhagwan/fzf-lua/commit/15e9b1f1494dc1facaffe9543281d015c43b9eba - this commits works around your issue by settings the defaults of blines to no icons/colors (as the file is a hidden field in blines anyways).

sandangel commented 1 year ago

@ibhagwan okay I think I found the issue, there is no DevIconLua, but there is DevIconlua. You might want to normalize the word case of devicon.

sandangel commented 1 year ago
image

the right hand side is fzf-lua files, the left hand side is nvim-tree. Nvim tree can pickup the icon correctly, but fzf-lua doesn't

sandangel commented 1 year ago
vim.g.nvchad_theme = 'onedark'

return {
  'nvim-tree/nvim-web-devicons',
  dependencies = { { 'NvChad/ui', branch = 'v2.0' }, { 'NvChad/base46', branch = 'v2.0' } },
  config = function()
    local colors = require('base46').get_theme_tb 'base_30'
    local override = vim.tbl_deep_extend('force', require('nvchad_ui.icons').devicons, {
      default_icon = { color = colors.red },
      c = { color = colors.blue, name = 'C' },
      css = { color = colors.blue },
      deb = { color = colors.cyan },
      Dockerfile = { color = colors.cyan },
      html = { color = colors.baby_pink },
      jpeg = { color = colors.dark_purple },
      jpg = { color = colors.dark_purple },
      js = { color = colors.sun },
      kt = { color = colors.orange },
      lock = { color = colors.red },
      lua = { color = colors.blue },
      mp3 = { color = colors.white },
      mp4 = { color = colors.white },
      out = { color = colors.white },
      png = { color = colors.dark_purple },
      py = { color = colors.cyan },
      toml = { color = colors.blue },
      ts = { color = colors.teal },
      ttf = { color = colors.white },
      rb = { color = colors.pink },
      rpm = { color = colors.orange },
      vue = { color = colors.vibrant_green },
      woff = { color = colors.white },
      woff2 = { color = colors.white },
      xz = { color = colors.sun },
      zip = { color = colors.sun },
      ['robots.txt'] = { color = colors.blue },
      ['docker-compose.yaml'] = {
        icon = '',
        name = 'DockerCompose',
        color = colors.cyan,
      },
      ['.dockerignore'] = {
        icon = '',
        name = 'DockerIgnore',
        color = colors.cyan,
      },
      yaml = {
        icon = '',
        name = 'yaml',
        color = colors.orange,
      },
      hcl = {
        icon = '',
        color = colors.green,
        name = 'hcl',
      },
      json = {
        icon = '',
        color = colors.green,
        name = 'Json',
      },
      md = {
        icon = '',
        color = colors.vibrant_green,
        name = 'md',
      },
      sh = {
        icon = '',
        color = colors.yellow,
        name = 'sh',
      },
      sql = {
        icon = '',
        color = colors.red,
        name = 'sql',
      },
    })
    require('nvim-web-devicons').setup {
      override = override
    }
  end
}

this is my web-dev-icons settings using Lazy if you would like to reproduce

ibhagwan commented 1 year ago

the right hand side is fzf-lua files, the left hand side is nvim-tree. Nvim tree can pickup the icon correctly, but fzf-lua doesn't

Nvim-tree gets the neovim highlights directly from devicons, FzfLua can’t do that, it has to recreate a new set of highlight escape codes for the terminal (as fzf runs in the terminal).

@ibhagwan okay I think I found the issue, there is no DevIconLua, but there is DevIconlua. You might want to normalize the word case of devicon.

I thought about it before but this turned out to never be an issue, the issue is just with your setup since you’re overriding the name property, whats the purpose of doing so?

What if you override the name completely not just change the capitalization? It shouldn’t matter as long as devicons returns the same name from both geticons and geticon.

What’s the output of :lua _G.dump(require"nvim-web-devicons".get_icon("1.lua","lua",{default=true}))? Is it Lua or lua?

sandangel commented 1 year ago

@ibhagwan I got this one: "" "DevIconlua"

ibhagwan commented 1 year ago

@ibhagwan I got this one: "" "DevIconlua"

Everything is working as expected.

I just tried icon override with devicons and it also works as expected:

require("nvim-web-devicons").setup({
  override = {
    lua = {
      icon = "",
      color = "#89e051",
      cterm_color = "113",
      name = "luaicon",
    },
  },
})

My lua icons now look like terminal icons, and :lua _G.dump(require"nvim-web-devicons".get_icon("1.lua","lua",{default=true})) returns: "" "DevIconluaicon" - the case doesn't need to be normalized and both fzf-lua and devicons are adpating accordingly.

This issue is different than the original issue, you have no lua exceptions, the icons are picked up properly but the icon chosen for docker seems to have a font rendering issue within the neovim terminal (as I wrote above, fzf-lua runs fzf inside a neovim terminal).

Try to change docker to a different icon, for example change it to a and I expect it will work, figure out why your font doesn't render this icon within the neovim terminal and you'll have your solution.

ibhagwan commented 1 year ago

The issue is devicons defaults for Dockerfile contains an icon that's not part of nerd fonts, I suspect you have a custom definition for "special files" in nvim-tree that's why it works, you need to add an override to Dockerfile to get the result you want:

require("nvim-web-devicons").setup({
  override = {
    Dockerfile = {
      icon = "",
      color = "#458ee6",
      cterm_color = "33",
      name = "Dockerfile",
    },
  },
})
sandangel commented 1 year ago

@ibhagwan

The issue is devicons defaults for Dockerfile contains an icon that's not part of nerd fonts, I suspect you have a custom definition for "special files" in nvim-tree that's why it works

I think this is not correct. I have a code override like you mentioned already in web-devicons config. There is nothing specific.

    local override = vim.tbl_deep_extend('force', require('nvchad_ui.icons').devicons, {
      default_icon = { color = colors.red },
      c = { color = colors.blue, name = 'C' },
      css = { color = colors.blue },
      deb = { color = colors.cyan },
      Dockerfile = { color = colors.cyan }   -- <<----- this line

So I just reuse the table defined here and add colors to it using tbl_deep_extend

https://github.com/NvChad/ui/blob/v2.0/lua/nvchad_ui/icons.lua#L44

sandangel commented 1 year ago
image

I also changed the icon to a but it doesn't work either.

sandangel commented 1 year ago
image

I also open nvim terminal and tried ls, it also showed dockerfile icon correctly

ibhagwan commented 1 year ago
sandangel commented 1 year ago
ibhagwan commented 1 year ago

"" "DevIconDockerfile"

This seems accurate.

I set icon to letter a as above and it still doesn't work

I understand your issue now, by default, overrides do not work with providers that use multiprocess (files, grep, etc), as these providers spawn in an external process, if you try lines (which doesn't run in an external process) you will see it works.

To apply your overrides in the external process read this: https://github.com/ibhagwan/fzf-lua/wiki#how-can-i-use-custom-devicons-with-multiprocess

You'll need to move your devicons overrides to a separate file (with its limitations), see #657, #386, #311.

ibhagwan commented 1 year ago

@sandangel, https://github.com/ibhagwan/fzf-lua/commit/604eadfcf69b90cf9e508767ad217107520ce4d4 - this commits makes my previous post moot, everything should now work as expected including overrides without additional setup.

Let me know if this works as expected now?

sandangel commented 1 year ago

okay now it works as expected. thanks a lot for fixing.

ibhagwan commented 1 year ago

okay now it works as expected. thanks a lot for fixing.

Great, ty for the update!