@@ -51,10 +51,12 @@ function M.belongs_to_active_session(question_request)
5151 return false
5252end
5353
54+ --- Request the renderer to show the current question display.
5455local function render_question ()
5556 require (' opencode.ui.renderer.events' ).render_question_display ()
5657end
5758
59+ --- Request the renderer to remove the current question display.
5860local function clear_question ()
5961 require (' opencode.ui.renderer.events' ).clear_question_display ()
6062end
@@ -111,6 +113,7 @@ function M.restore_pending_question(session_id)
111113 end )
112114end
113115
116+ --- Reset the current question state and remove any dialog UI.
114117function M .clear_question ()
115118 M ._clear_dialog ()
116119 M ._current_question = nil
@@ -161,6 +164,8 @@ local function answer_current_question(answer_value)
161164 end )
162165end
163166
167+ --- @param options OpencodeQuestionOption[]
168+ --- @return integer | nil
164169local function find_other_option (options )
165170 for i , opt in ipairs (options ) do
166171 if vim .startswith (opt .label :lower (), ' other' ) then
@@ -170,6 +175,8 @@ local function find_other_option(options)
170175 return nil
171176end
172177
178+ --- @param question_info OpencodeQuestionInfo
179+ --- @return integer
173180local function get_total_options (question_info )
174181 local has_other = find_other_option (question_info .options ) ~= nil
175182 return has_other and # question_info .options or (# question_info .options + 1 )
@@ -198,6 +205,7 @@ function M._answer_with_option(option_index)
198205 answer_current_question (question_info .options [option_index ].label )
199206end
200207
208+ --- Prompt for a free-form answer to the active question.
201209function M ._answer_with_custom ()
202210 vim .ui .input ({ prompt = ' Enter your response: ' }, function (input )
203211 if input and input ~= ' ' then
@@ -210,6 +218,8 @@ function M._answer_with_custom()
210218 end )
211219end
212220
221+ --- @param options OpencodeQuestionOption[]
222+ --- @return OpencodeQuestionOption[]
213223local function add_other_if_missing (options )
214224 if find_other_option (options ) ~= nil then
215225 return options
@@ -258,6 +268,7 @@ function M.format_display(output)
258268 })
259269end
260270
271+ --- Create the in-buffer dialog used to answer the active question.
261272function M ._setup_dialog ()
262273 if not M .has_question () then
263274 return
@@ -272,11 +283,13 @@ function M._setup_dialog()
272283
273284 local buf = state .windows .output_buf
274285
286+ --- @return boolean
275287 local function check_focused ()
276288 local ui = require (' opencode.ui.ui' )
277289 return ui .is_opencode_focused () and M .has_question ()
278290 end
279291
292+ --- @param index integer
280293 local function on_select (index )
281294 if not check_focused () then
282295 return
@@ -289,6 +302,7 @@ function M._setup_dialog()
289302 end , 100 )
290303 end
291304
305+ --- Reject the current question if the dialog is dismissed.
292306 local function on_dismiss ()
293307 if not check_focused () then
294308 return
@@ -298,10 +312,12 @@ function M._setup_dialog()
298312 render_question ()
299313 end
300314
315+ --- Refresh the rendered question state after navigation changes.
301316 local function on_navigate ()
302317 render_question ()
303318 end
304319
320+ --- @return integer
305321 local function get_option_count ()
306322 local question_info = M .get_current_question_info ()
307323 return question_info and get_total_options (question_info ) or 0
@@ -320,6 +336,7 @@ function M._setup_dialog()
320336 M ._dialog :setup ()
321337end
322338
339+ --- Tear down the active question dialog, if any.
323340function M ._clear_dialog ()
324341 if M ._dialog then
325342 M ._dialog :teardown ()
0 commit comments