Skip to content

Commit e02416b

Browse files
committed
feat: add fzf-lua file preview and line navigation support
Add builtin previewer support to fzf-lua picker backend with automatic line/column positioning for code references. Changes: - Enable 'builtin' previewer when preview='file' - Append file:line:col: format to entries for fzf-lua parsing - Update fn_fzf_index to strip position info before matching - Supports navigation to specific lines (range highlighting shows start line only) Implementation details: - Uses tab separator between display text and file position - fzf-lua's entry_to_file() automatically parses path:line:col: format - Cursorline highlights the target line in preview - Gracefully degrades when preview is disabled Comparison with other pickers: - Telescope: Full range highlighting (start-end lines) - Snacks: Full range highlighting (start-end lines) - fzf-lua: Single line highlighting (cursorline at start) - Mini.pick: No file preview support
1 parent 7fdcf41 commit e02416b

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

lua/opencode/ui/base_picker.lua

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,13 @@ local function fzf_ui(opts)
209209
['--multi'] = has_multi_action and true or nil,
210210
},
211211
_headers = { 'actions' },
212+
-- Enable builtin previewer for file preview support
213+
previewer = opts.preview == 'file' and 'builtin' or nil,
212214
fn_fzf_index = function(line)
215+
-- Strip the appended file:line:col info before matching
216+
local display_part = line:match('^([^\t]+)') or line
213217
for i, item in ipairs(opts.items) do
214-
if opts.format_fn(item):to_string() == line then
218+
if opts.format_fn(item):to_string() == display_part then
215219
return i
216220
end
217221
end
@@ -223,7 +227,31 @@ local function fzf_ui(opts)
223227
local function create_finder()
224228
return function(fzf_cb)
225229
for _, item in ipairs(opts.items) do
226-
fzf_cb(opts.format_fn(item):to_string())
230+
local line_str = opts.format_fn(item):to_string()
231+
232+
-- For file preview support, append file:line:col format
233+
-- fzf-lua's builtin previewer automatically parses this format
234+
if opts.preview == 'file' and type(item) == 'table' then
235+
local file_path = item.file or item.file_path or item.path or item.filename
236+
local line = item.line or item.lnum
237+
local col = item.column or item.col
238+
239+
if file_path then
240+
-- fzf-lua parses "path:line:col:" format for preview positioning
241+
local pos_info = file_path
242+
if line then
243+
pos_info = pos_info .. ':' .. tostring(line)
244+
if col then
245+
pos_info = pos_info .. ':' .. tostring(col)
246+
end
247+
pos_info = pos_info .. ':'
248+
end
249+
-- Append position info after tab separator (fzf-lua standard)
250+
line_str = line_str .. '\t' .. pos_info
251+
end
252+
end
253+
254+
fzf_cb(line_str)
227255
end
228256
fzf_cb()
229257
end

0 commit comments

Comments
 (0)