trouble.nvim icon indicating copy to clipboard operation
trouble.nvim copied to clipboard

Keep Trouble window quickfix list up to date as the document is edited

Open Hubro opened this issue 3 years ago • 1 comments

Currently, using :Trouble quickfix with gives a worse developer experience than using the built-in quickfix window plus :cnext/:cprevious.

The quickfix :cnext/:cprevious commands will jump to the correct line even if you've added/deleted lines higher up in the document. However, Trouble with require("trouble").next/previous(...) will jump to the exact line number from the quickfix list.

Any time I fix a linter warning, jumping to the next linter warning will take me to an unrelated line, which is a massive pain. After a few fixes, the jump location may not even be anywhere near the location of the linter warning, making the Trouble quickfix list useless.

Should the locations in the Trouble quickfix window be kept up-to-date as lines are added/deleted from the document? This would make it much, much easier to work with. Are there any drawbacks to doing this?


The logic sounds pretty trivial, and it would have to run any time a line is added or deleted:

  • Any time a line is added, any quickfix list item with a higher line number than the added line should have its row number incremented by one
  • Any time a line is deleted, any quickfix list item with a higher line number than the deleted line should have its row number decremented by one

I'm not very familiar with writing plugins for Vim/NVim, but I assume there are autocommands that trigger on document edits and APIs for figuring out which lines were added/removed.

Hubro avatar Aug 08 '22 20:08 Hubro

Or, come to think of it, perhaps pressing <Enter> on a line in Trouble could just execute the same action that would be executed in the built-in quickfix list? That way, whatever logic Vim is doing to keep the line number up to date would be reused.

Hubro avatar Dec 01 '22 11:12 Hubro

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

folke avatar Mar 29 '24 07:03 folke