@@ -423,18 +423,27 @@ function M._format_user_message(text, message)
423423
424424 if context .current_file then
425425 M .output :add_empty_line ()
426- local path = context .current_file or ' '
427- if vim .startswith (path , vim .fn .getcwd ()) then
428- path = path :sub (# vim .fn .getcwd () + 2 )
429- end
430- M .output :add_line (string.format (' [%s](%s)' , path , context .current_file ))
426+ M ._format_context_file (context .current_file )
431427 end
432428
433429 local end_line = M .output :get_line_count ()
434430
435431 M ._add_vertical_border (start_line , end_line , ' OpencodeMessageRoleUser' , - 3 )
436432end
437433
434+ --- Format and display the file path in the context
435+ --- @param path string | nil File path
436+ function M ._format_context_file (path )
437+ if not path or path == ' ' then
438+ return
439+ end
440+ local cwd = vim .fn .getcwd ()
441+ if vim .startswith (path , cwd ) then
442+ path = path :sub (# cwd + 2 )
443+ end
444+ return M .output :add_line (string.format (' [%s](%s)' , path , path ))
445+ end
446+
438447--- @param text string
439448function M ._format_assistant_message (text )
440449 -- M.output:add_empty_line()
@@ -750,11 +759,7 @@ function M.format_part_isolated(part, message_info)
750759 M ._format_patch (part )
751760 content_added = true
752761 elseif part .type == ' file' then
753- local path = part .filename
754- if vim .startswith (path , vim .fn .getcwd ()) then
755- path = path :sub (# vim .fn .getcwd () + 2 )
756- end
757- local file_line = M .output :add_line (string.format (' [%s](%s)' , path , part .filename ))
762+ local file_line = M ._format_context_file (part .filename )
758763 if message_info .role == ' user' then
759764 -- when streaming, the file comes in as a separate event, connect it to user
760765 -- message
0 commit comments