Skip to content

Commit 95ffb46

Browse files
committed
fix: the second picker couldn't open any file
Due to options being changed for the first picker (in particular, a custom formatter is set), the second picker was unable to open any file, it would only point to folders. This commit fixes this behavior by passing down only the user options to the second picker, along with the ones specifically needed by it. Fixes #46
1 parent fb61acb commit 95ffb46

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

lua/telescope/_extensions/repo/main.lua

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,21 @@ local function project_live_grep(opts)
130130
require("telescope.builtin").live_grep(opts)
131131
end
132132

133-
local function call_picker(opts, command, prompt_title_supplement)
133+
local function call_picker(list_opts, command, prompt_title_supplement, user_opts)
134+
if list_opts == nil then
135+
error("Incorrect call to call_picker, list_opts should be specified to pass relevant options to the first picker")
136+
end
137+
if user_opts == nil then
138+
error("Incorrect call to call_picker, user_opts should be specified to pass relevant options to the second picker")
139+
end
140+
134141
local prompt_title = "Git repositories"
135142
if prompt_title_supplement ~= nil then
136143
prompt_title = prompt_title .. prompt_title_supplement
137144
end
138-
pickers.new(opts, {
145+
pickers.new(list_opts, {
139146
prompt_title = prompt_title,
140-
finder = finders.new_oneshot_job(command, opts),
147+
finder = finders.new_oneshot_job(command, list_opts),
141148
previewer = previewers.new_termopen_previewer({
142149
get_command = function(entry)
143150
local dir = Path:new(from_entry.path(entry))
@@ -156,28 +163,28 @@ local function call_picker(opts, command, prompt_title_supplement)
156163
return utils.find_generic_previewer_for_document(doc.filename)
157164
end,
158165
}),
159-
sorter = conf.file_sorter(opts),
166+
sorter = conf.file_sorter(list_opts),
160167
attach_mappings = function(prompt_bufnr)
161168
actions_set.select:replace(function(_, type)
162169
local entry = actions_state.get_selected_entry()
163170
local dir = from_entry.path(entry)
164171
if type == "default" then
165172
actions._close(prompt_bufnr, false)
166173
vim.schedule(function()
167-
project_files(vim.tbl_extend("force", opts, { cwd = dir }))
174+
project_files(vim.tbl_extend("force", user_opts, { cwd = dir }))
168175
end)
169176
end
170177
if type == "vertical" then
171178
actions._close(prompt_bufnr, false)
172179
vim.schedule(function()
173-
project_live_grep(vim.tbl_extend("force", opts, { cwd = dir }))
180+
project_live_grep(vim.tbl_extend("force", list_opts, { cwd = dir }))
174181
end)
175182
return
176183
end
177184
if type == "tab" then
178185
vim.cmd("tabe " .. dir)
179186
vim.cmd("tcd " .. dir)
180-
project_files(vim.tbl_extend("force", opts, { cwd = dir }))
187+
project_files(vim.tbl_extend("force", list_opts, { cwd = dir }))
181188
return
182189
end
183190
end)
@@ -188,20 +195,22 @@ end
188195

189196
-- List of repos built using locate (or variants)
190197
M.cached_list = function(opts)
191-
opts = vim.tbl_deep_extend("force", r_config.values.cached_list or {}, opts or {})
192-
opts.entry_maker = t_utils.get_lazy_default(opts.entry_maker, gen_from_locate_wrapper, opts)
193-
local locate_command = cached_list.prepare_command(opts)
198+
local common_opts = opts or {}
199+
local list_opts = vim.tbl_deep_extend("force", r_config.values.cached_list or {}, common_opts)
200+
list_opts.entry_maker = t_utils.get_lazy_default(list_opts.entry_maker, gen_from_locate_wrapper, list_opts)
201+
local locate_command = cached_list.prepare_command(list_opts)
194202

195-
call_picker(opts, locate_command, " (cached)")
203+
call_picker(list_opts, locate_command, " (cached)", common_opts)
196204
end
197205

198206
-- Always up to date list of repos built using fd
199207
M.list = function(opts)
200-
opts = vim.tbl_deep_extend("force", r_config.values.list or {}, opts or {})
201-
opts.entry_maker = t_utils.get_lazy_default(opts.entry_maker, gen_from_fd, opts)
202-
local fd_command = list.prepare_command(opts)
208+
local common_opts = opts or {}
209+
local list_opts = vim.tbl_deep_extend("force", r_config.values.list or {}, common_opts)
210+
list_opts.entry_maker = t_utils.get_lazy_default(list_opts.entry_maker, gen_from_fd, list_opts)
211+
local fd_command = list.prepare_command(list_opts)
203212

204-
call_picker(opts, fd_command, " (built on the fly)")
213+
call_picker(list_opts, fd_command, " (built on the fly)", common_opts)
205214
end
206215

207216
return M

0 commit comments

Comments
 (0)