|
| 1 | +local util = require('opencode.util') |
| 2 | +local helpers = require('opencode.ui.formatter.tools.helpers') |
| 3 | + |
| 4 | +local M = {} |
| 5 | + |
| 6 | +---@param ctx table |
| 7 | +function M.format(ctx) |
| 8 | + local input = ctx.input or {} |
| 9 | + local metadata = ctx.metadata or {} |
| 10 | + local tool_output = ctx.tool_output |
| 11 | + local tool_type = ctx.tool_type |
| 12 | + |
| 13 | + local file_name = tool_type == 'read' and helpers.resolve_display_file_name(input.filePath or '', tool_output) |
| 14 | + or helpers.resolve_file_name(input.filePath or '') |
| 15 | + |
| 16 | + local file_type = input.filePath and util.get_markdown_filetype(input.filePath) or '' |
| 17 | + |
| 18 | + ctx.format_action(ctx.output, tool_type, tool_type, file_name, ctx.duration_text) |
| 19 | + |
| 20 | + if not ctx.config.ui.output.tools.show_output then |
| 21 | + return |
| 22 | + end |
| 23 | + |
| 24 | + if tool_type == 'edit' and metadata.diff then |
| 25 | + ctx.format_diff(ctx.output, metadata.diff, file_type) |
| 26 | + elseif tool_type == 'write' and input.content then |
| 27 | + ctx.format_code(ctx.output, vim.split(input.content, '\n'), file_type) |
| 28 | + end |
| 29 | +end |
| 30 | + |
| 31 | +---@param part OpencodeMessagePart |
| 32 | +---@param input FileToolInput |
| 33 | +---@return string, string, string |
| 34 | +function M.summary(part, input) |
| 35 | + local tool = part.tool |
| 36 | + if tool == 'read' then |
| 37 | + local tool_output = part.state and part.state.output or nil |
| 38 | + return 'read', 'read', helpers.resolve_display_file_name(input.filePath, tool_output) |
| 39 | + end |
| 40 | + return tool, tool, helpers.resolve_file_name(input.filePath) |
| 41 | +end |
| 42 | + |
| 43 | +return M |
0 commit comments