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 v3: using ':trouble.next' when cursor isn't in the trouble buffer often doesn't work #402

Closed rgauselumifi closed 1 month ago

rgauselumifi commented 3 months ago

Did you check docs and existing issues?

Neovim version (nvim -v)

0.10

Operating system/version

Ubuntu 22.04

Describe the bug

Most of the time, after running something like ':Trouble qflist toggle', if i then call ':lua require('trouble').next()' or ':Trouble next', it doesn't work correctly. If I move my cursor into the trouble window, and then execute ':lua require('trouble').next()', it does work.

This bug happens 80% of the time, but occasionally doesn't. To be clear, it only doesn't work if my cursor is not in the trouble buffer.

Steps To Reproduce

  1. Get data in quickfix list (using grep or whatever)
  2. Execute ":Trouble qflist toggle"
  3. Your cursor should still be in your original buffer, not the trouble one. Now execute "lua require('trouble').next()" or ":Trouble next"
  4. Most of the time, there will be a quick glitch like the screen is being redrawn, and you won't have moved to the next item in the list.

Expected Behavior

Should work with cursor outside of the buffer.

PS: side note, I noticed if I run the 'next' function when the trouble window is closed that an error occurs as the 'mode' has not been specified. I'm curious if there's a way to have the mode default to the last used one. That way if I populate the qflist or diagnostic list, I could close the trouble window and still navigate through the results.

Love the plugin, cheers my friend

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

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

The keymaps from LazyVim appear to be broken in version 3 too (I changed require("trouble").previous(.. to the new api; require("trouble").prev(..):

https://github.com/LazyVim/LazyVim/blob/97480dc5d2dbb717b45a351e0b04835f138a9094/lua/lazyvim/plugins/editor.lua#L463-L492

folke commented 1 month ago

This should be fixed now. Do let me know if you'd still encounter this!