@@ -43,10 +43,12 @@ local Promise = require('opencode.promise')
4343--- @class MiniPickSelected
4444--- @field current MiniPickItem ?
4545
46+ --- @class PickerItemPart
47+ --- @field text string The text content
48+ --- @field highlight ? string Optional highlight group
49+
4650--- @class PickerItem
47- --- @field content string Main content text
48- --- @field time_text ? string Optional time text
49- --- @field debug_text ? string Optional debug text
51+ --- @field parts PickerItemPart[] Array of text parts with optional highlights
5052--- @field to_string fun ( self : PickerItem ): string
5153--- @field to_formatted_text fun ( self : PickerItem ): table
5254
@@ -80,24 +82,35 @@ local function telescope_ui(opts)
8082 local action_state = require (' telescope.actions.state' )
8183 local action_utils = require (' telescope.actions.utils' )
8284 local entry_display = require (' telescope.pickers.entry_display' )
83- local displayer = entry_display .create ({
84- separator = ' ' ,
85- items = { {}, {}, config .debug .show_ids and {} or nil },
86- })
85+
86+ -- Create displayer dynamically based on number of parts
87+ local function create_displayer (picker_item )
88+ local items = {}
89+ for _ in ipairs (picker_item .parts ) do
90+ table.insert (items , {})
91+ end
92+ return entry_display .create ({
93+ separator = ' ' ,
94+ items = items ,
95+ })
96+ end
8797
8898 local current_picker
8999
90100 --- Creates entry maker function for telescope
91101 --- @param item any
92102 --- @return TelescopeEntry
93103 local function make_entry (item )
104+ local picker_item = opts .format_fn (item )
105+ local displayer = create_displayer (picker_item )
106+
94107 local entry = {
95108 value = item ,
96109 display = function (entry )
97110 local formatted = opts .format_fn (entry .value ):to_formatted_text ()
98111 return displayer (formatted )
99112 end ,
100- ordinal = opts . format_fn ( item ) :to_string (),
113+ ordinal = picker_item :to_string (),
101114 }
102115
103116 if type (item ) == ' table' then
@@ -549,35 +562,70 @@ function M.align(text, width, opts)
549562end
550563
551564--- Creates a generic picker item that can format itself for different pickers
552- --- @param text string Array of text parts to join
553- --- @param time ? number Optional time text to highlight
565+ --- @param parts PickerItemPart[] Array of text parts with optional highlights
566+ --- @return PickerItem
567+ function M .create_picker_item (parts )
568+ local item = {
569+ parts = parts ,
570+ }
571+
572+ function item :to_string ()
573+ local texts = {}
574+ for _ , part in ipairs (self .parts ) do
575+ table.insert (texts , part .text )
576+ end
577+ return table.concat (texts , ' ' )
578+ end
579+
580+ function item :to_formatted_text ()
581+ local formatted = {}
582+ for _ , part in ipairs (self .parts ) do
583+ if part .highlight then
584+ table.insert (formatted , { ' ' .. part .text , part .highlight })
585+ else
586+ table.insert (formatted , { part .text })
587+ end
588+ end
589+ return formatted
590+ end
591+
592+ return item
593+ end
594+
595+ --- Helper function to create a simple picker item with content, time, and debug text
596+ --- This is a convenience wrapper around create_picker_item for common use cases
597+ --- @param text string Main content text
598+ --- @param time ? number Optional time to format
554599--- @param debug_text ? string Optional debug text to append
555600--- @param width ? number Optional width override
556601--- @return PickerItem
557- function M .create_picker_item (text , time , debug_text , width )
602+ function M .create_time_picker_item (text , time , debug_text , width )
558603 local time_width = time and # util .format_time (time ) + 1 or 0
559604 local debug_width = config .debug .show_ids and debug_text and # debug_text + 1 or 0
560605 local item_width = width or vim .api .nvim_win_get_width (0 )
561606 local text_width = item_width - (debug_width + time_width )
562- local item = {
563- content = M .align (text , text_width --[[ @as integer]] , { truncate = true }),
564- time_text = time and M .align (util .format_time (time ), time_width , { align = ' right' }),
565- debug_text = config .debug .show_ids and debug_text or nil ,
607+
608+ local parts = {
609+ {
610+ text = M .align (text , text_width --[[ @as integer]] , { truncate = true }),
611+ },
566612 }
567613
568- function item :to_string ()
569- return table.concat ({ self .content , self .time_text or ' ' , self .debug_text or ' ' }, ' ' )
614+ if time then
615+ table.insert (parts , {
616+ text = M .align (util .format_time (time ), time_width , { align = ' right' }),
617+ highlight = ' OpencodePickerTime' ,
618+ })
570619 end
571620
572- function item :to_formatted_text ()
573- return {
574- { self .content },
575- self .time_text and { ' ' .. self .time_text , ' OpencodePickerTime' } or { ' ' },
576- self .debug_text and { ' ' .. self .debug_text , ' OpencodeDebugText' } or { ' ' },
577- }
621+ if config .debug .show_ids and debug_text then
622+ table.insert (parts , {
623+ text = debug_text ,
624+ highlight = ' OpencodeDebugText' ,
625+ })
578626 end
579627
580- return item
628+ return M . create_picker_item ( parts )
581629end
582630
583631--- Generic picker that abstracts common logic for different picker UIs
0 commit comments