@@ -50,78 +50,64 @@ export function InteractiveDiffViewer({ data, onFunctionSelect }: InteractiveDif
5050 const [ selectedFunction , setSelectedFunction ] = useState < string | null > ( null ) ;
5151 const [ isFullscreen , setIsFullscreen ] = useState ( false ) ;
5252
53- // Generate mock diff data from the graph match result
53+ // Generate diff data from the real comparison result
5454 const diffSections = useMemo ( ( ) => {
55- if ( ! data ) return [ ] ;
55+ if ( ! data || ! data . functionMatches ) return [ ] ;
5656
5757 const sections : DiffSection [ ] = [ ] ;
5858
5959 // Process function matches
60- data . matches . forEach ( ( match , index ) => {
61- const sourceLines : DiffLine [ ] = [
62- { lineNumber : 1 , content : `function ${ match . source_id } () {` , type : 'unchanged' } ,
63- { lineNumber : 2 , content : ' // Original implementation' , type : 'removed' } ,
64- { lineNumber : 3 , content : ' return originalValue;' , type : 'removed' } ,
65- { lineNumber : 4 , content : ' // Updated implementation' , type : 'added' } ,
66- { lineNumber : 5 , content : ' return updatedValue;' , type : 'added' } ,
67- { lineNumber : 6 , content : '}' , type : 'unchanged' } ,
68- ] ;
60+ data . functionMatches . forEach ( ( match , index ) => {
61+ const sourceName = match . sourceFunction ?. name || 'N/A' ;
62+ const targetName = match . targetFunction ?. name || 'N/A' ;
63+ const sourceContent = match . sourceFunction ?. content || '' ;
64+ const targetContent = match . targetFunction ?. content || '' ;
6965
70- const targetLines : DiffLine [ ] = [
71- { lineNumber : 1 , content : `function ${ match . target_id } () {` , type : 'unchanged' } ,
72- { lineNumber : 2 , content : ' // Updated implementation' , type : 'added' } ,
73- { lineNumber : 3 , content : ' return updatedValue;' , type : 'added' } ,
74- { lineNumber : 4 , content : '}' , type : 'unchanged' } ,
75- ] ;
66+ // Split content into lines for diff display
67+ let sourceLines : DiffLine [ ] = [ ] ;
68+ let targetLines : DiffLine [ ] = [ ] ;
7669
77- sections . push ( {
78- functionName : match . source_id ,
79- sourceLines,
80- targetLines,
81- similarity : match . similarity . overall_similarity ,
82- confidence : match . confidence ,
83- matchType : match . match_type ,
84- } ) ;
85- } ) ;
86-
87- // Process additions
88- data . additions . forEach ( ( funcId ) => {
89- const targetLines : DiffLine [ ] = [
90- { lineNumber : 1 , content : `function ${ funcId } () {` , type : 'added' } ,
91- { lineNumber : 2 , content : ' // New function implementation' , type : 'added' } ,
92- { lineNumber : 3 , content : ' return newValue;' , type : 'added' } ,
93- { lineNumber : 4 , content : '}' , type : 'added' } ,
94- ] ;
70+ if ( sourceContent ) {
71+ sourceLines = sourceContent . split ( '\n' ) . map ( ( line , i ) => ( {
72+ lineNumber : i + 1 ,
73+ content : line ,
74+ type : match . type === 'deleted' ? 'removed' :
75+ match . changes ?. bodyChanged ? 'removed' : 'unchanged'
76+ } ) ) ;
77+ }
9578
96- sections . push ( {
97- functionName : funcId ,
98- sourceLines : [ ] ,
99- targetLines,
100- similarity : 0 ,
101- confidence : 1 ,
102- matchType : 'Addition' ,
103- } ) ;
104- } ) ;
79+ if ( targetContent ) {
80+ targetLines = targetContent . split ( '\n' ) . map ( ( line , i ) => ( {
81+ lineNumber : i + 1 ,
82+ content : line ,
83+ type : match . type === 'added' ? 'added' :
84+ match . changes ?. bodyChanged ? 'added' : 'unchanged'
85+ } ) ) ;
86+ }
10587
106- // Process deletions
107- data . deletions . forEach ( ( funcId ) => {
108- const sourceLines : DiffLine [ ] = [
109- { lineNumber : 1 , content : `function ${ funcId } () {` , type : 'removed' } ,
110- { lineNumber : 2 , content : ' // Deleted function implementation' , type : 'removed' } ,
111- { lineNumber : 3 , content : ' return deletedValue;' , type : 'removed' } ,
112- { lineNumber : 4 , content : '}' , type : 'removed' } ,
113- ] ;
88+ // If no content available, create placeholder
89+ if ( sourceLines . length === 0 && targetLines . length === 0 ) {
90+ const placeholderLines = [
91+ { lineNumber : 1 , content : `// Function: ${ sourceName } ` , type : 'unchanged' as const } ,
92+ { lineNumber : 2 , content : '// Content not available for preview' , type : 'unchanged' as const }
93+ ] ;
94+ sourceLines = [ ...placeholderLines ] ;
95+ targetLines = [ ...placeholderLines ] ;
96+ }
11497
11598 sections . push ( {
116- functionName : funcId ,
99+ functionName : sourceName ,
117100 sourceLines,
118- targetLines : [ ] ,
119- similarity : 0 ,
120- confidence : 1 ,
121- matchType : 'Deletion' ,
101+ targetLines,
102+ similarity : match . similarity ,
103+ confidence : match . similarity , // Use similarity as confidence
104+ matchType : match . type ,
122105 } ) ;
123106 } ) ;
124107
108+ // Process additions and deletions are already included in functionMatches
109+ // with type 'added' and 'deleted', so we don't need separate processing
110+
125111 return sections ;
126112 } , [ data ] ) ;
127113
0 commit comments