@@ -2,6 +2,8 @@ local state = require('opencode.state')
22local icons = require (' opencode.ui.icons' )
33local Dialog = require (' opencode.ui.dialog' )
44
5+ local config = require (' opencode.config' )
6+
57local M = {}
68
79M ._current_question = nil
@@ -27,8 +29,13 @@ function M.show_question(question_request)
2729 M ._current_question = question_request
2830 M ._current_question_index = 1
2931 M ._collected_answers = {}
30- M ._setup_dialog ()
31- render_question ()
32+
33+ if config .ui .questions and config .ui .questions .use_vim_ui_select then
34+ M ._show_question_with_vim_ui_select ()
35+ else
36+ M ._setup_dialog ()
37+ render_question ()
38+ end
3239end
3340
3441function M .clear_question ()
@@ -247,6 +254,60 @@ function M._clear_dialog()
247254 end
248255end
249256
257+ --- Show question using vim.ui.select
258+ function M ._show_question_with_vim_ui_select ()
259+ if not M .has_question () then
260+ return
261+ end
262+
263+ local question_info = M .get_current_question_info ()
264+ if not question_info or not question_info .options then
265+ return
266+ end
267+
268+ local options_to_display = add_other_if_missing (question_info .options )
269+ local progress = ' '
270+ if M ._current_question and # M ._current_question .questions > 1 then
271+ progress = string.format (' (%d/%d)' , M ._current_question_index , # M ._current_question .questions )
272+ end
273+
274+ local prompt = question_info .question .. progress
275+ local choices = {}
276+ for i , option in ipairs (options_to_display ) do
277+ table.insert (choices , option .label )
278+ end
279+
280+ vim .ui .select (choices , {
281+ prompt = prompt ,
282+ format_item = function (item )
283+ return item
284+ end ,
285+ }, function (choice )
286+ if not choice then
287+ -- User cancelled
288+ if M ._current_question and M ._current_question .id then
289+ M ._send_reject (M ._current_question .id )
290+ end
291+ M .clear_question ()
292+ return
293+ end
294+
295+ -- Find the selected option index
296+ local selected_index = nil
297+ for i , option in ipairs (options_to_display ) do
298+ if option .label == choice then
299+ selected_index = i
300+ break
301+ end
302+ end
303+
304+ if selected_index then
305+ M ._answering = true
306+ M ._answer_with_option (selected_index )
307+ end
308+ end )
309+ end
310+
250311--- @param request_id string
251312--- @param answers string[][]
252313function M ._send_reply (request_id , answers )
0 commit comments