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.44k stars 177 forks source link

feature: Allow additional options to be passed to sources #457

Closed Tired-Fox closed 4 months ago

Tired-Fox commented 4 months ago

Did you check the docs?

Is your feature request related to a problem? Please describe.

There is no problem, just a quality of life

Describe the solution you'd like

Currently, using require("trouble.sources.telescope").open only takes the passed buffer number from telescope. After adding the items to the trouble buffer, it opens the window with require("trouble").open("telescope").

It would be a nice quality of life to allow the user to pass additional options to the require("trouble.sources.telescope").open function. This would allow the user to change the auto focus, preview, and other options.

local open_with_trouble = require("trouble.sources.telescope").open
require("telescope").setup({
  defaults = {
    mappings = {
      n = { ["<c-t>"] =  open_with_trouble }
    }
  }
})

-- to something like

local open_with_trouble = function (bufnr)
  require("trouble.sources.telescope").open(bufnr, {
    focus = true,
    -- etc...
  })
end
require("telescope").setup({
  defaults = {
    mappings = {
      n = { ["<c-t>"] = open_with_trouble }
    }
  }
})

Maybe a table merge so that the end of trouble.sources.trouble.add can look something like this

function M.add(prompt_bufnr, opts)
  --- ... add items from buffer

  opts = vim.tbl_extend("force", {}, opts, { mode = "telescope" })
  vim.schedule(function()
    require("telescope.actions").close(prompt_bufnr),
    require("trouble").open(opts)
  end)
end

Describe alternatives you've considered

Alternatively the opening of the window could be pulled out and into the trouble.sources.telescope.open function itself

Additional context

No response