@@ -375,23 +375,19 @@ class SmartCodeDiffApp {
375375 }
376376
377377 isCodeFile ( filename ) {
378- const codeExtensions = [
379- '.c' , '.cpp' , '.cc' , '.cxx' , '.h' , '.hpp' , '.hxx' ,
380- '.js' , '.jsx' , '.ts' , '.tsx' , '.mjs' , '.cjs' ,
381- '.py' , '.pyx' , '.pyi' ,
382- '.java' , '.kt' , '.scala' ,
383- '.rs' , '.go' , '.rb' , '.php' ,
384- '.cs' , '.vb' , '.fs' ,
385- '.swift' , '.m' , '.mm' ,
386- '.sh' , '.bash' , '.zsh' ,
387- '.sql' , '.pl' , '.r' ,
388- '.html' , '.htm' , '.xml' ,
389- '.css' , '.scss' , '.sass' , '.less' ,
390- '.json' , '.yaml' , '.yml' , '.toml' ,
391- '.md' , '.txt' , '.cfg' , '.ini'
378+ // Only include extensions that the server actually supports
379+ const supportedExtensions = [
380+ '.c' , '.h' , // C
381+ '.cpp' , '.cc' , '.cxx' , '.hpp' , // C++
382+ '.js' , '.jsx' , // JavaScript
383+ '.ts' , '.tsx' , // TypeScript
384+ '.py' , '.pyw' , // Python
385+ '.java' , // Java
386+ '.rs' , // Rust
387+ '.go' // Go
392388 ] ;
393-
394- return codeExtensions . some ( ext => filename . toLowerCase ( ) . endsWith ( ext ) ) ;
389+
390+ return supportedExtensions . some ( ext => filename . toLowerCase ( ) . endsWith ( ext ) ) ;
395391 }
396392
397393 async handleFileSelection ( files , isDirectory ) {
@@ -448,31 +444,33 @@ class SmartCodeDiffApp {
448444 detectLanguage ( filename ) {
449445 const ext = filename . toLowerCase ( ) . split ( '.' ) . pop ( ) ;
450446 const languageMap = {
451- 'c' : 'C ' ,
452- 'cpp' : 'C++ ' , 'cc' : 'C++ ' , 'cxx' : 'C++ ' ,
453- 'h' : 'C/C++ ' , 'hpp' : 'C++ ' , 'hxx' : 'C++ ' ,
454- 'js' : 'JavaScript ' , 'jsx' : 'JavaScript ' , 'mjs' : 'JavaScript ' , 'cjs' : 'JavaScript ' ,
455- 'ts' : 'TypeScript ' , 'tsx' : 'TypeScript ' ,
456- 'py' : 'Python ' , 'pyx' : 'Python ' , 'pyi' : 'Python ' ,
457- 'java' : 'Java ' ,
458- 'kt' : 'Kotlin ' ,
459- 'rs' : 'Rust ' ,
460- 'go' : 'Go ' ,
461- 'rb' : 'Ruby ' ,
462- 'php' : 'PHP ' ,
463- 'cs' : 'C# ' ,
464- 'swift' : 'Swift ' ,
465- 'sh' : 'Shell ' , 'bash' : 'Shell ' , 'zsh' : 'Shell ' ,
466- 'sql' : 'SQL ' ,
467- 'html' : 'HTML ' , 'htm' : 'HTML ' ,
468- 'css' : 'CSS ' , 'scss' : 'SCSS ' , 'sass' : 'SASS ' ,
469- 'json' : 'JSON ' ,
470- 'yaml' : 'YAML ' , 'yml' : 'YAML ' ,
471- 'md' : 'Markdown ' ,
472- 'xml' : 'XML '
447+ 'c' : 'c ' ,
448+ 'cpp' : 'cpp ' , 'cc' : 'cpp ' , 'cxx' : 'cpp ' ,
449+ 'h' : 'c ' , 'hpp' : 'cpp ' , 'hxx' : 'cpp ' ,
450+ 'js' : 'javascript ' , 'jsx' : 'javascript ' , 'mjs' : 'javascript ' , 'cjs' : 'javascript ' ,
451+ 'ts' : 'typescript ' , 'tsx' : 'typescript ' ,
452+ 'py' : 'python ' , 'pyx' : 'python ' , 'pyi' : 'python ' ,
453+ 'java' : 'java ' ,
454+ 'kt' : 'kotlin ' ,
455+ 'rs' : 'rust ' ,
456+ 'go' : 'go ' ,
457+ 'rb' : 'ruby ' ,
458+ 'php' : 'php ' ,
459+ 'cs' : 'csharp ' ,
460+ 'swift' : 'swift ' ,
461+ 'sh' : 'bash ' , 'bash' : 'bash ' , 'zsh' : 'bash ' ,
462+ 'sql' : 'sql ' ,
463+ 'html' : 'html ' , 'htm' : 'html ' ,
464+ 'css' : 'css ' , 'scss' : 'css ' , 'sass' : 'css ' ,
465+ 'json' : 'json ' ,
466+ 'yaml' : 'yaml ' , 'yml' : 'yaml ' ,
467+ 'md' : 'markdown ' ,
468+ 'xml' : 'xml '
473469 } ;
474-
475- return languageMap [ ext ] || 'Unknown' ;
470+
471+ // Return the language in lowercase format that the server expects
472+ // Default to 'c' for unknown files since that's most likely to work
473+ return languageMap [ ext ] || 'c' ;
476474 }
477475
478476 updateFileTree ( ) {
@@ -953,19 +951,20 @@ class SmartCodeDiffApp {
953951
954952 // Compare all common files
955953 const comparisons = [ ] ;
954+ let successCount = 0 ;
955+ let errorCount = 0 ;
956+
956957 for ( const commonFile of commonFiles ) {
957- const options = {
958- threshold : parseFloat ( document . getElementById ( 'thresholdSlider' ) ?. value || 0.8 ) ,
959- ignore_whitespace : document . getElementById ( 'ignoreWhitespace' ) ?. checked || false ,
960- detect_moves : document . getElementById ( 'detectMoves' ) ?. checked || true
961- } ;
962-
963- const response = await fetch ( `${ this . apiBase } /compare` , {
964- method : 'POST' ,
965- headers : {
966- 'Content-Type' : 'application/json' ,
967- } ,
968- body : JSON . stringify ( {
958+ try {
959+ this . showLoading ( `Comparing files... (${ successCount + errorCount + 1 } /${ commonFiles . length } )` ) ;
960+
961+ const options = {
962+ threshold : parseFloat ( document . getElementById ( 'thresholdSlider' ) ?. value || 0.8 ) ,
963+ ignore_whitespace : document . getElementById ( 'ignoreWhitespace' ) ?. checked || false ,
964+ detect_moves : document . getElementById ( 'detectMoves' ) ?. checked || true
965+ } ;
966+
967+ const requestBody = {
969968 file1 : {
970969 path : commonFile . sourcePath ,
971970 content : commonFile . sourceFile . content
@@ -975,23 +974,88 @@ class SmartCodeDiffApp {
975974 content : commonFile . targetFile . content
976975 } ,
977976 options : options
978- } )
979- } ) ;
977+ } ;
980978
981- if ( ! response . ok ) {
982- throw new Error ( `HTTP ${ response . status } : ${ response . statusText } ` ) ;
983- }
979+ console . log ( 'Comparing files:' , commonFile . sourcePath , 'vs' , commonFile . targetPath ) ;
984980
985- const result = await response . json ( ) ;
986- comparisons . push ( {
987- ...commonFile ,
988- comparison : result
989- } ) ;
981+ const response = await fetch ( `${ this . apiBase } /compare` , {
982+ method : 'POST' ,
983+ headers : {
984+ 'Content-Type' : 'application/json' ,
985+ } ,
986+ body : JSON . stringify ( requestBody )
987+ } ) ;
988+
989+ if ( ! response . ok ) {
990+ const errorText = await response . text ( ) ;
991+ console . error ( `Error comparing ${ commonFile . name } :` , response . status , errorText ) ;
992+ errorCount ++ ;
993+
994+ // Add a placeholder comparison result for failed comparisons
995+ comparisons . push ( {
996+ ...commonFile ,
997+ comparison : {
998+ similarity : 0 ,
999+ analysis : {
1000+ changes : {
1001+ total_changes : 0 ,
1002+ detailed_changes : [ {
1003+ change_type : 'ERROR' ,
1004+ description : `Failed to compare: ${ response . status } ${ response . statusText } ` ,
1005+ confidence : 0
1006+ } ]
1007+ } ,
1008+ functions : { total_functions : 0 }
1009+ } ,
1010+ execution_time_ms : 0 ,
1011+ error : true
1012+ }
1013+ } ) ;
1014+ continue ;
1015+ }
1016+
1017+ const result = await response . json ( ) ;
1018+ comparisons . push ( {
1019+ ...commonFile ,
1020+ comparison : result
1021+ } ) ;
1022+ successCount ++ ;
1023+
1024+ } catch ( error ) {
1025+ console . error ( `Exception comparing ${ commonFile . name } :` , error ) ;
1026+ errorCount ++ ;
1027+
1028+ // Add error placeholder
1029+ comparisons . push ( {
1030+ ...commonFile ,
1031+ comparison : {
1032+ similarity : 0 ,
1033+ analysis : {
1034+ changes : {
1035+ total_changes : 0 ,
1036+ detailed_changes : [ {
1037+ change_type : 'ERROR' ,
1038+ description : `Exception: ${ error . message } ` ,
1039+ confidence : 0
1040+ } ]
1041+ } ,
1042+ functions : { total_functions : 0 }
1043+ } ,
1044+ execution_time_ms : 0 ,
1045+ error : true
1046+ }
1047+ } ) ;
1048+ }
9901049 }
9911050
9921051 this . displayBranchComparisonResults ( comparisons ) ;
9931052 this . hideLoading ( ) ;
994- this . showToast ( `Compared ${ comparisons . length } files between branches` , 'success' ) ;
1053+
1054+ if ( errorCount > 0 ) {
1055+ this . showToast ( `Compared ${ successCount } files successfully, ${ errorCount } failed` , 'warning' ) ;
1056+ } else {
1057+ this . showToast ( `Successfully compared ${ successCount } files between branches` , 'success' ) ;
1058+ }
9951059
9961060 } catch ( error ) {
9971061 this . hideLoading ( ) ;
@@ -1049,11 +1113,16 @@ class SmartCodeDiffApp {
10491113 const similarityClass = comp . comparison . similarity > 0.9 ? 'high' :
10501114 comp . comparison . similarity > 0.7 ? 'medium' : 'low' ;
10511115
1116+ const isError = comp . comparison . error ;
1117+ const errorClass = isError ? 'error' : '' ;
1118+
10521119 return `
1053- <div class="file-comparison-item">
1120+ <div class="file-comparison-item ${ errorClass } ">
10541121 <div class="file-comparison-header">
10551122 <span class="file-name">${ comp . name } </span>
1056- <span class="similarity-badge ${ similarityClass } ">${ similarity } %</span>
1123+ <span class="similarity-badge ${ isError ? 'error' : similarityClass } ">
1124+ ${ isError ? 'ERROR' : similarity + '%' }
1125+ </span>
10571126 </div>
10581127 <div class="file-paths">
10591128 <div class="path-item">
0 commit comments