-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathquestion.lua
More file actions
55 lines (44 loc) · 1.69 KB
/
question.lua
File metadata and controls
55 lines (44 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
local M = {}
---@param output Output
---@param part OpencodeMessagePart
function M.format(output, part)
if part.tool ~= 'question' then
return
end
local input = part.state and part.state.input or {}
local metadata = part.state and part.state.metadata or {}
local utils = require('opencode.ui.formatter.utils')
local config = require('opencode.config')
-- question tool never shows duration
local icons = require('opencode.ui.icons')
utils.format_action(output, icons.get('question'), 'question', '', nil)
output:add_empty_line()
local start_line = output:get_line_count() + 1
if not (config.ui.output.tools.show_output or config.ui.output.tools.use_folds) or (part.state and part.state.status) ~= 'completed' then
return
end
local questions = input.questions or {}
local answers = metadata.answers or {}
for i, question in ipairs(questions) do
local question_lines = vim.split(question.question, '\n')
if #question_lines > 1 then
output:add_line(string.format('**Q%d:** %s', i, question.header))
for _, line in ipairs(question_lines) do
output:add_line(line)
end
else
output:add_line(string.format('**Q%d:** %s', i, question_lines[1]))
end
local answer = answers[i] and answers[i][1] or 'No answer'
local answer_lines = vim.split(answer, '\n', { plain = true })
output:add_line(string.format('**A%d:** %s', i, answer_lines[1]))
for line_idx = 2, #answer_lines do
output:add_line(answer_lines[line_idx])
end
if i < #questions then
output:add_line('')
end
end
output:add_fold_with_threshold(start_line, config.ui.output.tools.show_output, config.ui.output.tools.use_folds)
end
return M