|
513 | 513 | ---@param tool_type string Tool type (e.g., 'read', 'edit', 'write') |
514 | 514 | ---@param input FileToolInput data for the tool |
515 | 515 | ---@param metadata FileToolMetadata Metadata for the tool use |
| 516 | +---@param tool_output? string Tool output payload for detecting directory reads |
516 | 517 | ---@param duration_text? string |
517 | | -function M._format_file_tool(output, tool_type, input, metadata, duration_text) |
518 | | - local file_name = M._resolve_file_name(input and input.filePath or '') |
| 518 | +function M._format_file_tool(output, tool_type, input, metadata, tool_output, duration_text) |
| 519 | + local file_name = tool_type == 'read' and M._resolve_display_file_name(input and input.filePath or '', tool_output) |
| 520 | + or M._resolve_file_name(input and input.filePath or '') |
519 | 521 |
|
520 | 522 | local file_type = input and util.get_markdown_filetype(input.filePath) or '' |
521 | 523 |
|
@@ -679,6 +681,34 @@ function M._resolve_file_name(file_path) |
679 | 681 | return absolute |
680 | 682 | end |
681 | 683 |
|
| 684 | +---@param file_path string |
| 685 | +---@param tool_output? string |
| 686 | +---@return boolean |
| 687 | +function M._is_directory_path(file_path, tool_output) |
| 688 | + if not file_path or file_path == '' then |
| 689 | + return false |
| 690 | + end |
| 691 | + |
| 692 | + if vim.endswith(file_path, '/') then |
| 693 | + return true |
| 694 | + end |
| 695 | + |
| 696 | + return type(tool_output) == 'string' and tool_output:match('<type>directory</type>') ~= nil |
| 697 | +end |
| 698 | + |
| 699 | +---@param file_path string |
| 700 | +---@param tool_output? string |
| 701 | +---@return string |
| 702 | +function M._resolve_display_file_name(file_path, tool_output) |
| 703 | + local resolved = M._resolve_file_name(file_path) |
| 704 | + |
| 705 | + if resolved ~= '' and M._is_directory_path(file_path, tool_output) and not vim.endswith(resolved, '/') then |
| 706 | + resolved = resolved .. '/' |
| 707 | + end |
| 708 | + |
| 709 | + return resolved |
| 710 | +end |
| 711 | + |
682 | 712 | function M._resolve_grep_string(input) |
683 | 713 | if not input then |
684 | 714 | return '' |
@@ -714,7 +744,14 @@ function M._format_tool(output, part, get_child_parts) |
714 | 744 | if tool == 'bash' then |
715 | 745 | M._format_bash_tool(output, input --[[@as BashToolInput]], metadata --[[@as BashToolMetadata]], duration_text) |
716 | 746 | elseif tool == 'read' or tool == 'edit' or tool == 'write' then |
717 | | - M._format_file_tool(output, tool, input --[[@as FileToolInput]], metadata --[[@as FileToolMetadata]], duration_text) |
| 747 | + M._format_file_tool( |
| 748 | + output, |
| 749 | + tool, |
| 750 | + input --[[@as FileToolInput]], |
| 751 | + metadata --[[@as FileToolMetadata]], |
| 752 | + tool_output, |
| 753 | + duration_text |
| 754 | + ) |
718 | 755 | elseif tool == 'todowrite' then |
719 | 756 | M._format_todo_tool(output, part.state.title, input --[[@as TodoToolInput]], duration_text) |
720 | 757 | elseif tool == 'glob' then |
@@ -775,8 +812,9 @@ local tool_summary_handlers = { |
775 | 812 | bash = function(_, input) |
776 | 813 | return 'run', 'run', input.description or '' |
777 | 814 | end, |
778 | | - read = function(_, input) |
779 | | - return 'read', 'read', M._resolve_file_name(input.filePath) |
| 815 | + read = function(part, input) |
| 816 | + local tool_output = part.state and part.state.output or nil |
| 817 | + return 'read', 'read', M._resolve_display_file_name(input.filePath, tool_output) |
780 | 818 | end, |
781 | 819 | edit = function(_, input) |
782 | 820 | return 'edit', 'edit', M._resolve_file_name(input.filePath) |
|
0 commit comments