Skip to content

Commit e93b47c

Browse files
committed
feat(ui): add preview support to telescope picker
- populate entry path, lnum, and col in telescope entries to support previewers - enable file previewer configuration when options request file preview - ensures code references can be previewed directly in the telescope picker UI
1 parent 1612d8f commit e93b47c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lua/opencode/ui/base_picker.lua

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,24 @@ local function telescope_ui(opts)
9090
---@param item any
9191
---@return TelescopeEntry
9292
local function make_entry(item)
93-
return {
93+
local entry = {
9494
value = item,
9595
display = function(entry)
9696
local formatted = opts.format_fn(entry.value):to_formatted_text()
9797
return displayer(formatted)
9898
end,
9999
ordinal = opts.format_fn(item):to_string(),
100100
}
101+
102+
if type(item) == 'table' then
103+
entry.path = item.file or item.file_path or item.path or item.filename
104+
entry.lnum = item.line or item.lnum
105+
entry.col = item.column or item.col
106+
elseif type(item) == 'string' then
107+
entry.path = item
108+
end
109+
110+
return entry
101111
end
102112

103113
local function refresh_picker()
@@ -112,6 +122,7 @@ local function telescope_ui(opts)
112122
prompt_title = opts.title,
113123
finder = finders.new_table({ results = opts.items, entry_maker = make_entry }),
114124
sorter = conf.generic_sorter({}),
125+
previewer = opts.preview == 'file' and conf.file_previewer({}) or nil,
115126
layout_config = opts.width and {
116127
width = opts.width + 7, -- extra space for telescope UI
117128
} or nil,

0 commit comments

Comments
 (0)