Skip to content

Commit 7dc718b

Browse files
committed
feat: add tool type check for formatters
1 parent f20f99e commit 7dc718b

8 files changed

Lines changed: 44 additions & 2 deletions

File tree

lua/opencode/ui/formatter/tools/apply_patch.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ end
2020
---@param output Output
2121
---@param part OpencodeMessagePart
2222
function M.format(output, part)
23+
if part.tool ~= 'apply_patch' then
24+
return
25+
end
26+
2327
local metadata = part.state and part.state.metadata or {}
2428
for _, file in ipairs(metadata.files or {}) do
2529
local utils = require('opencode.ui.formatter.utils')

lua/opencode/ui/formatter/tools/glob.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ local M = {}
33
---@param output Output
44
---@param part OpencodeMessagePart
55
function M.format(output, part)
6+
if part.tool ~= 'glob' then
7+
return
8+
end
9+
610
local input = part.state and part.state.input or {}
711
local metadata = part.state and part.state.metadata or {}
812

lua/opencode/ui/formatter/tools/grep.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ end
1919
---@param output Output
2020
---@param part OpencodeMessagePart
2121
function M.format(output, part)
22+
if part.tool ~= 'grep' then
23+
return
24+
end
25+
2226
local metadata = part.state and part.state.metadata or {}
2327
local input = part.state and part.state.input or nil
2428

lua/opencode/ui/formatter/tools/list.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ local M = {}
33
---@param output Output
44
---@param part OpencodeMessagePart
55
function M.format(output, part)
6+
if part.tool ~= 'list' then
7+
return
8+
end
69
local input = part.state and part.state.input or {}
710
local metadata = part.state and part.state.metadata or {}
811
local tool_output = part.state and part.state.output or ''

lua/opencode/ui/formatter/tools/question.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ local M = {}
33
---@param output Output
44
---@param part OpencodeMessagePart
55
function M.format(output, part)
6+
if part.tool ~= 'question' then
7+
return
8+
end
9+
610
local input = part.state and part.state.input or {}
711
local metadata = part.state and part.state.metadata or {}
812

lua/opencode/ui/formatter/tools/task.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ end
2525
---@param part OpencodeMessagePart
2626
---@param get_child_parts? fun(session_id: string): OpencodeMessagePart[]?
2727
function M.format(output, part, get_child_parts)
28+
if part.tool ~= 'task' then
29+
return
30+
end
31+
2832
local input = part.state and part.state.input or {}
2933
local metadata = part.state and part.state.metadata or {}
3034
local tool_output = part.state and part.state.output or ''

lua/opencode/ui/formatter/tools/todowrite.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@ local M = {}
33
---@param output Output
44
---@param part OpencodeMessagePart
55
function M.format(output, part)
6+
if part.tool ~= 'todowrite' then
7+
return
8+
end
69
local utils = require('opencode.ui.formatter.utils')
710
local config = require('opencode.config')
811

912
local icons = require('opencode.ui.icons')
10-
utils.format_action(output, icons.get('plan'), 'plan', (part.state and part.state.title or ''), utils.get_duration_text(part))
13+
utils.format_action(
14+
output,
15+
icons.get('plan'),
16+
'plan',
17+
(part.state and part.state.title or ''),
18+
utils.get_duration_text(part)
19+
)
1120
if not config.ui.output.tools.show_output then
1221
return
1322
end

lua/opencode/ui/formatter/tools/webfetch.lua

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,18 @@ local utils = require('opencode.ui.formatter.utils')
44
---@param output Output
55
---@param part OpencodeMessagePart
66
function M.format(output, part)
7+
if part.tool ~= 'webfetch' then
8+
return
9+
end
10+
711
local icons = require('opencode.ui.icons')
8-
utils.format_action(output, icons.get('web'), 'fetch', part.state and part.state.input and part.state.input.url, utils.get_duration_text(part))
12+
utils.format_action(
13+
output,
14+
icons.get('web'),
15+
'fetch',
16+
part.state and part.state.input and part.state.input.url,
17+
utils.get_duration_text(part)
18+
)
919
end
1020

1121
---@param _ OpencodeMessagePart

0 commit comments

Comments
 (0)