folke / trouble.nvim

🚦 A pretty diagnostics, references, telescope results, quickfix and location list to help you solve all the trouble your code is causing.
Apache License 2.0
5.15k stars 173 forks source link

bug: fatal error when `nvim-web-devicons` is installed but an icon is unavailable for the current file #383

Closed jthvai closed 3 months ago

jthvai commented 4 months ago

Did you check docs and existing issues?

Neovim version (nvim -v)

0.9.5

Operating system/version

Arch Linux (up-to-date 2024-02-22)

Describe the bug

When icons = true in Trouble's config, but an icon is not available for a filetype/extension, the Trouble window will fail to open with:

E5108: Error executing lua .../.repro/plugins/trouble.nvim/lua/trouble/view.lua:368: Error executing lua: .../.repro/plugins/trouble.nvim/lua/trouble/text.lua:22: attempt to index local 'str' (a nil value)

when there are diagnostics.

I believe this is because gsub is called here (text.lua L22) on str without a nil check, but get_icons called here (renderer.lua L108) can still return nil as the ok check in its definition here (renderer L13) only checks whether devicons is installed, not if it can actually return an icon for the given require("nvim-web-devicons").get_icon.

Steps To Reproduce

  1. nvim -u repro.lua test.py
  2. Type something that generates a diagnostic, such as def: only and exiting insert mode
  3. Open the trouble window (:TroubleToggle)

Expected Behavior

Ideally, Trouble should simply not render an icon for that file, like icons = false.

example

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  "folke/trouble.nvim",
  -- add any other plugins here
  {
    "nvim-tree/nvim-web-devicons",
    opts = {
      override_by_extension = {
        ["py"] = {},
      }
    }
  },

  -- To generate diagnostics
  "neovim/nvim-lspconfig",
  {
    dir = "",
    name = "lspconfig-jedils",
    ft = "python",
    dependencies = "neovim/nvim-lspconfig",
    config = function(_, opts)
      require "lspconfig".jedi_language_server.setup(opts)
    end
  }
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
folke commented 3 months ago

Development on the main branch is EOL.

Trouble has been rewritten and will be merged in main soon.

This issue/feature either no longer exists or has been implemented on dev.

For more info, see https://github.com/folke/trouble.nvim/tree/dev