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.12k stars 172 forks source link

bug v3: `auto_close` and `auto_open` broken #419

Closed simonmandlik closed 1 month ago

simonmandlik commented 2 months ago

Did you check docs and existing issues?

Neovim version (nvim -v)

NVIM v0.10.0-dev-2949+g206475d79-Homebrew

Operating system/version

MacOS 14.4.1

Describe the bug

I can't get auto_open and auto_close to work even in the simplest configuration. Am I missing something?

Steps To Reproduce

  1. nvim -u repro.lua
  2. <leader>a, <leader>r
  3. <leader>xx
  4. <leader>a, <leader>r

Expected Behavior

I would expect the Trouble window to open after first <leader>a, and close after last <leader>r.

Actual behavior:

https://github.com/folke/trouble.nvim/assets/16707112/1bb164f9-54e9-434a-af77-e874e06cb0f3

Thanks for the plugin!

Repro

Btw, the issue template for v3 doesn't contain branch = "dev", this may lead some people into installing v2 when creating MWEs by mistakes.

-- 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",
        branch = "dev",
        keys = {
            {
                "<leader>xx",
                "<cmd>Trouble diagnostics toggle<cr>",
                desc = "Diagnostics (Trouble)",
            },
        },
        opts = {
            auto_close = true,
            auto_open = true,
        }
    },
    {
        "nvim-treesitter/nvim-treesitter",
        build = ":TSUpdate",
        config = function ()
            require("nvim-treesitter.configs").setup {
                ensure_installed = { "markdown", "markdown_inline" },
            }
        end
    },
}

require("lazy").setup(plugins, {
    root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

local ns = vim.api.nvim_create_namespace("test")

vim.keymap.set("n", "<leader>a", function()
    print("Adding diagnostics")
    vim.diagnostic.set(ns, 0, {{
        lnum=0,
        col=0,
        message="test",
        severity = vim.diagnostic.severity.ERROR,
    }})
end)

vim.keymap.set("n", "<leader>r", function()
    print("Removing diagnostics")
    vim.diagnostic.reset()
end)
ejconlon commented 2 months ago

I have also noticed that the latest version of trouble auto closes too early (when resolving the current error, not all errors).

folke commented 1 month ago

Should be fixed now. Thank you for the detailed bug report!