Skip to content

Commit

Permalink
feat(telescope): allow passing additional trouble options to telescop…
Browse files Browse the repository at this point in the history
…e open/add. Fixes #457
  • Loading branch information
folke committed May 31, 2024
1 parent daf2c60 commit 4eaaf9c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lua/trouble/sources/telescope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ function M.get(cb, _ctx)
end

-- Append the current telescope buffer to the trouble list.
function M.add(prompt_bufnr)
---@param opts? trouble.Mode|string
function M.add(prompt_bufnr, opts)
local action_state = require("telescope.actions.state")
---@type Picker
local picker = action_state.get_current_picker(prompt_bufnr)
Expand All @@ -70,15 +71,21 @@ function M.add(prompt_bufnr)

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

-- Opens the current telescope buffer in the trouble list.
-- This will clear the existing items.
function M.open(prompt_bufnr)
---@param opts? trouble.Mode|string
function M.open(prompt_bufnr, opts)
M.items = {}
M.add(prompt_bufnr)
M.add(prompt_bufnr, opts)
end

return M

0 comments on commit 4eaaf9c

Please sign in to comment.