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.45k stars 177 forks source link

bug v3: Trouble crashes in v2 and v3 when selecting a diagnostic published for a directory #410

Closed MXfive closed 4 months ago

MXfive commented 6 months ago

Did you check docs and existing issues?

Neovim version (nvim -v)

v0.9.5 Release

Operating system/version

macOS 14.4.1

Describe the bug

Some diagnostic sources such as Trivy / Tfsec can report findings against directories in addition to files. V2 and V3 of Trouble both error if you move your cursor over one of these findings.

Steps To Reproduce

  1. Install terraform and tflint
  2. In an empty directory, create a main.tf file with the contents: provider "aws" {}
  3. Run the command terraform init from within that folder
  4. Open main.tf with the repro config below
  5. Run :lua require('lint').try_lint()
  6. Run :Trouble diagnostics (or :Trouble workspace_diagnostics for v2)
  7. Scroll down to the last finding for the directory
  8. Boom

Expected Behavior

There should be 2 findings reported, 1 in the local file and another on the module folder. (this makes sense in the context of a Terraform module since any file in the directory could define the version constraint as reported)

    ~/Code/  2 
   ├╴  poc/  1 
   │ └╴  main.tf  1 
   │   └╴  Missing version constraint for provider "aws" in `required_providers`  () [2, 0]
   └╴  poc  1 
     └╴  terraform "required_version" attribute is required  () [1, -1]

When hovering over the last line in the trouble window, Trouble will rapidly repeat calls to try and read the folder's path as if it were a file, giving a flurry of messages:

   Error  21:59:55 notify.error Trouble ....local/share/nvim/lazy/trouble.nvim/lua/trouble/util.lua:222: EISDIR: illegal operation on a directory

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",
    "mfussenegger/nvim-lint",
}
require("lazy").setup(plugins, {
    root = root .. "/plugins",
})

require("trouble").setup()
local lint = require("lint")
lint.linters_by_ft = {
    terraform = { "tfsec" },
}

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

Should be fixed now. Thank you for reporting!

MXfive commented 4 months ago

Verified, cheers!