Is your feature request related to a problem? Please describe.
When I use Neovim LSP features like "go to definition" or "go to references", sometimes there's only one result that gets jumped to immediately, and sometimes there's a list of results, presented to the user as a qflist. I'd like to use Trouble instead of the qflist. Many of the Neovim LSP functions can take an optional on_list handler like so:
vim.lsp.buf.definition{on_list=on_list}
There's built-in modes in Trouble for some of these, but not vim.lsp.buf.declaration or vim.lsp.buf.implementation, and there's nothing in the documented API for opening Trouble with a given set of results.
Describe the solution you'd like
I'd like a function analogous to trouble.providers.telescope.open_with_trouble, named something like trouble.providers.lsp.on_list, which can be used as an on_list callback.
Ideally, if there's only one item in the list, that item will be opened directly, and if there's multiple items a Trouble window will be opened.
Describe alternatives you've considered
I could build this function myself if there was a way to populate a Trouble window from a list of results, but the only interface appears to be the trouble.open and trouble.toggle functions, both of which just take a mode string rather than a structured list of items.
I think it would be a good idea to have a trouble.open_items function or similar, even if I suspect an on_list callback is a useful enough feature that it's worth shipping on its own.
I can also build this feature myself (hackily), by first setting the qflist or loclist from the items in the on_list handler and then opening Trouble in the qflist or loclist modes. Unfortunately, this will open Trouble even if there's one (or worse, zero) results, so it leaves something to be desired. It also feels awkward that I have to use the loclist as an intermediate buffer rather than being able to convert into Trouble's desired representation myself.
Did you check the docs?
Is your feature request related to a problem? Please describe.
When I use Neovim LSP features like "go to definition" or "go to references", sometimes there's only one result that gets jumped to immediately, and sometimes there's a list of results, presented to the user as a
qflist
. I'd like to useTrouble
instead of theqflist
. Many of the Neovim LSP functions can take an optionalon_list
handler like so:There's built-in modes in Trouble for some of these, but not
vim.lsp.buf.declaration
orvim.lsp.buf.implementation
, and there's nothing in the documented API for opening Trouble with a given set of results.Describe the solution you'd like
I'd like a function analogous to
trouble.providers.telescope.open_with_trouble
, named something liketrouble.providers.lsp.on_list
, which can be used as anon_list
callback.Ideally, if there's only one item in the list, that item will be opened directly, and if there's multiple items a Trouble window will be opened.
Describe alternatives you've considered
I could build this function myself if there was a way to populate a Trouble window from a list of results, but the only interface appears to be the
trouble.open
andtrouble.toggle
functions, both of which just take a mode string rather than a structured list of items.I think it would be a good idea to have a
trouble.open_items
function or similar, even if I suspect anon_list
callback is a useful enough feature that it's worth shipping on its own.I can also build this feature myself (hackily), by first setting the
qflist
orloclist
from the items in theon_list
handler and then opening Trouble in theqflist
orloclist
modes. Unfortunately, this will open Trouble even if there's one (or worse, zero) results, so it leaves something to be desired. It also feels awkward that I have to use theloclist
as an intermediate buffer rather than being able to convert into Trouble's desired representation myself.