Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
3 tasks done
MXfive opened this issue Apr 3, 2024 · 2 comments
Closed
3 tasks done
Labels

Comments

@MXfive
Copy link

MXfive commented Apr 3, 2024

Did you check docs and existing issues?

  • I have read all the trouble.nvim docs
  • I have searched the existing issues of trouble.nvim
  • I have searched the existing issues of plugins related to this issue

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
@MXfive MXfive added the bug v3 label Apr 3, 2024
@MXfive MXfive changed the title bug v3: bug v3: Trouble crashes in v2 and v3 when selecting a diagnostic published for a directory Apr 5, 2024
@folke folke closed this as completed May 12, 2024
@folke
Copy link
Owner

folke commented May 12, 2024

Should be fixed now. Thank you for reporting!

@MXfive
Copy link
Author

MXfive commented May 13, 2024

Verified, cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants