@@ -34,6 +34,7 @@ import {
3434 delete_checkpoint ,
3535 promote_temporary_checkpoint
3636} from '../checkpoints-command/actions'
37+ import { FileInReview } from '@shared/types/file-in-review'
3738
3839let ongoing_review_cleanup_promise : Promise < void > | null = null
3940
@@ -382,6 +383,7 @@ export const apply_chat_response_command = (
382383 file_path : string
383384 position : { line : number ; character : number }
384385 }
386+ files_with_content ?: FileInReview [ ]
385387 } ) => {
386388 if ( ! vscode . workspace . workspaceFolders ?. length ) {
387389 vscode . window . showErrorMessage (
@@ -442,6 +444,16 @@ export const apply_chat_response_command = (
442444 is_single_root_folder_workspace
443445 } )
444446
447+ if ( args ?. files_with_content ) {
448+ clipboard_content = {
449+ type : 'files' ,
450+ files : args . files_with_content as ClipboardFile [ ]
451+ }
452+ }
453+
454+ console . log ( 'xxx' , args ?. files_with_content )
455+ console . log ( 'xxx' , clipboard_content )
456+
445457 if (
446458 clipboard_content . type == 'code-completion' &&
447459 clipboard_content . code_completion
@@ -949,59 +961,79 @@ export const apply_chat_response_command = (
949961
950962 try {
951963 if ( review_data ) {
952- let total_lines_added = 0
953- let total_lines_removed = 0
964+ if ( ! args ?. files_with_content ) {
965+ let total_lines_added = 0
966+ let total_lines_removed = 0
967+ const files_for_history : FileInReview [ ] = [ ]
968+
969+ const workspace_map = new Map < string , string > ( )
970+ vscode . workspace . workspaceFolders ! . forEach ( ( folder ) => {
971+ workspace_map . set ( folder . name , folder . uri . fsPath )
972+ } )
973+ const default_workspace =
974+ vscode . workspace . workspaceFolders ! [ 0 ] . uri . fsPath
975+
976+ for ( const state of review_data . original_states ) {
977+ let workspace_root = default_workspace
978+ if (
979+ state . workspace_name &&
980+ workspace_map . has ( state . workspace_name )
981+ ) {
982+ workspace_root = workspace_map . get ( state . workspace_name ) !
983+ }
954984
955- const workspace_map = new Map < string , string > ( )
956- vscode . workspace . workspaceFolders ! . forEach ( ( folder ) => {
957- workspace_map . set ( folder . name , folder . uri . fsPath )
958- } )
959- const default_workspace =
960- vscode . workspace . workspaceFolders ! [ 0 ] . uri . fsPath
985+ const sanitized_file_path = create_safe_path (
986+ workspace_root ,
987+ state . file_path
988+ )
989+ if ( ! sanitized_file_path ) {
990+ continue
991+ }
961992
962- for ( const state of review_data . original_states ) {
963- let workspace_root = default_workspace
964- if (
965- state . workspace_name &&
966- workspace_map . has ( state . workspace_name )
967- ) {
968- workspace_root = workspace_map . get ( state . workspace_name ) !
969- }
993+ let current_content = ''
994+ try {
995+ if ( fs . existsSync ( sanitized_file_path ) ) {
996+ current_content = fs . readFileSync ( sanitized_file_path , 'utf8' )
997+ }
998+ } catch ( error ) {
999+ continue
1000+ }
9701001
971- const sanitized_file_path = create_safe_path (
972- workspace_root ,
973- state . file_path
974- )
975- if ( ! sanitized_file_path ) {
976- continue
977- }
1002+ const diff_stats = get_diff_stats ( {
1003+ original_content : state . content ,
1004+ new_content : current_content
1005+ } )
9781006
979- let current_content = ''
980- try {
981- if ( fs . existsSync ( sanitized_file_path ) ) {
982- current_content = fs . readFileSync ( sanitized_file_path , 'utf8' )
983- }
984- } catch ( error ) {
985- continue
1007+ total_lines_added += diff_stats . lines_added
1008+ total_lines_removed += diff_stats . lines_removed
1009+
1010+ const is_deleted =
1011+ ! state . is_new && current_content === '' && state . content !== ''
1012+
1013+ files_for_history . push ( {
1014+ file_path : state . file_path ,
1015+ workspace_name : state . workspace_name ,
1016+ is_new : state . is_new ,
1017+ is_deleted,
1018+ lines_added : diff_stats . lines_added ,
1019+ lines_removed : diff_stats . lines_removed ,
1020+ is_fallback : state . is_fallback ,
1021+ is_replaced : state . is_replaced ,
1022+ diff_fallback_method : state . diff_fallback_method ,
1023+ content : current_content
1024+ } )
9861025 }
9871026
988- const diff_stats = get_diff_stats ( {
989- original_content : state . content ,
990- new_content : current_content
1027+ view_provider . send_message ( {
1028+ command : 'NEW_RESPONSE_RECEIVED' ,
1029+ response : review_data . chat_response ,
1030+ raw_instructions : args ?. raw_instructions ,
1031+ lines_added : total_lines_added ,
1032+ lines_removed : total_lines_removed ,
1033+ files : files_for_history
9911034 } )
992-
993- total_lines_added += diff_stats . lines_added
994- total_lines_removed += diff_stats . lines_removed
9951035 }
9961036
997- view_provider . send_message ( {
998- command : 'NEW_RESPONSE_RECEIVED' ,
999- response : review_data . chat_response ,
1000- raw_instructions : args ?. raw_instructions ,
1001- lines_added : total_lines_added ,
1002- lines_removed : total_lines_removed
1003- } )
1004-
10051037 const changes_accepted = await handle_code_review_and_cleanup ( {
10061038 original_states : review_data . original_states ,
10071039 chat_response : review_data . chat_response ,
0 commit comments