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: closing trouble after using a trouble command in netrw breaks trouble #377

Closed darricheng closed 3 months ago

darricheng commented 5 months ago

Did you check docs and existing issues?

Neovim version (nvim -v)

0.9.5

Operating system/version

MacOS 14.2.1

Describe the bug

See title.

I get the following error:

E5108: Error executing lua ....local/share/nvim/lazy/trouble.nvim/lua/trouble/view.lua:355: BufLeave Autocommands for "<buffer=9>": Vim(lua):E5108: Error executing lua ....local/share/nvim/lazy/trouble.nvim/lua/trouble/view.lua:249: Cursor position outside buffer
stack traceback:
    [C]: in function 'nvim_win_set_cursor'
    ....local/share/nvim/lazy/trouble.nvim/lua/trouble/view.lua:249: in function 'close_preview'
    ....local/share/nvim/lazy/trouble.nvim/lua/trouble/view.lua:233: in function 'on_leave'
    ....local/share/nvim/lazy/trouble.nvim/lua/trouble/init.lua:218: in function 'action'
    [string ":lua"]:1: in main chunk
    [C]: in function 'nvim_set_current_win'
    ....local/share/nvim/lazy/trouble.nvim/lua/trouble/view.lua:355: in function 'close'
    ....local/share/nvim/lazy/trouble.nvim/lua/trouble/init.lua:28: in function 'close'
    ....local/share/nvim/lazy/trouble.nvim/lua/trouble/init.lua:96: in function 'toggle'
    [string ":lua"]:1: in main chunk
stack traceback:
    [C]: in function 'nvim_set_current_win'
    ....local/share/nvim/lazy/trouble.nvim/lua/trouble/view.lua:355: in function 'close'
    ....local/share/nvim/lazy/trouble.nvim/lua/trouble/init.lua:28: in function 'close'
    ....local/share/nvim/lazy/trouble.nvim/lua/trouble/init.lua:96: in function 'toggle'
    [string ":lua"]:1: in main chunk

Steps To Reproduce

  1. Go to netrw file explorer in neovim
  2. Use a Trouble command, such as :TroubleToggle workspace_diagnostics (or :TodoTrouble in the minimal repro to do the next step without lsp errors)
  3. Navigate to a line with an issue so that the file with the issue is displayed in the active buffer, i.e. where netrw was previously shown
  4. Attempt to close Trouble with :TroubleToggle

Expected Behavior

The Trouble window should close and return the active buffer to netrw.

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
  {
    "folke/todo-comments.nvim",
    dependencies = { "nvim-lua/plenary.nvim" },
    opts = {}
  }
}
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