Skip to content

Commit 1dcd373

Browse files
authored
Merge pull request #332 from shaurabh-tiwari-git/apexFullFileDiff
@ W-18480465 - Apex full file diff
2 parents cbf7b3b + 9a48aa6 commit 1dcd373

File tree

2 files changed

+71
-47
lines changed

2 files changed

+71
-47
lines changed

src/styles/reportGenerator.css

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,28 +256,30 @@ html {
256256
background-color: #fff;
257257
margin: auto;
258258
padding: 20px;
259+
padding-top: 20px;
259260
width: 60%;
260-
height: 60%;
261+
max-height: 80%;
261262
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
262263
border-radius: 4px;
263264
text-align: left;
264265
position: relative;
266+
overflow-y: auto;
267+
overflow-x: auto;
265268
}
266269

267270
.closeButton {
268271
color: #222121;
269-
height: 30px;
270-
width: 30px;
272+
height: 40px;
273+
width: 40px;
271274
position: absolute;
272-
background-color: #fff;
273-
top: -35px;
274-
right: 0;
275-
font-size: 25px;
275+
top: 0px;
276+
right: 0px;
277+
font-size: 30px;
276278
cursor: pointer;
277279
display: flex;
278280
align-items: center;
279281
justify-content: center;
280-
border-radius: 3px;
282+
z-index: 1050;
281283
}
282284

283285
.modalHeader {

src/utils/lwcparser/fileutils/FileDiffUtil.ts

Lines changed: 61 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -62,57 +62,79 @@ export class FileDiffUtil {
6262
}
6363

6464
public getFileDiff(filename: string, originalFileContent: string, modifiedFileContent: string): DiffPair[] {
65-
const patch: string = createPatch('', originalFileContent, modifiedFileContent);
6665
try {
67-
// Split the patch into lines
66+
const originalLines = originalFileContent.split('\n');
67+
const modifiedLines = modifiedFileContent.split('\n');
68+
const patch: string = createPatch('', originalFileContent, modifiedFileContent);
6869
const patchLines = patch.split('\n');
6970

70-
// Initialize variables to track line numbers
71-
let oldLineNumber = 1;
72-
let newLineNumber = 1;
73-
let firstPlusAlreadySkipped = false;
74-
let firstMinusAlreadySkipped = false;
75-
const diff: DiffPair[] = [];
76-
// Initialize result as HTML string
71+
let origIdx = 0;
72+
let modIdx = 0;
73+
const result: DiffPair[] = [];
7774

78-
patchLines.forEach((line) => {
79-
// Parse the hunk header (e.g., @@ -2,3 +2,3 @@)
80-
const hunkHeader = /^@@ -(\d+),\d+ \+(\d+),\d+ @@/;
75+
// Skip the first line of the patch (the file header)
76+
let i = 0;
77+
while (i < patchLines.length) {
78+
const line = patchLines[i];
79+
const hunkHeader = /^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@/;
8180
const match = hunkHeader.exec(line);
8281

8382
if (match) {
84-
oldLineNumber = parseInt(match[1], 10);
85-
newLineNumber = parseInt(match[2], 10);
86-
} else if (line.startsWith('-')) {
87-
// Skip the first line difference
88-
if (oldLineNumber === 1 && !firstMinusAlreadySkipped) {
89-
firstMinusAlreadySkipped = true;
90-
// Skip the first line difference
91-
oldLineNumber++;
92-
return;
83+
// Move to the start of the hunk
84+
const origStart = parseInt(match[1], 10) - 1;
85+
const modStart = parseInt(match[3], 10) - 1;
86+
87+
// Emit unchanged lines before the hunk
88+
while (origIdx < origStart && modIdx < modStart) {
89+
result.push({ old: originalLines[origIdx], new: modifiedLines[modIdx] });
90+
origIdx++;
91+
modIdx++;
9392
}
94-
diff.push({ old: line.slice(1), new: null });
95-
oldLineNumber++;
96-
} else if (line.startsWith('+')) {
97-
// Skip the first line difference
98-
if (newLineNumber === 1 && !firstPlusAlreadySkipped) {
99-
firstPlusAlreadySkipped = true;
100-
newLineNumber++;
101-
return;
93+
94+
i++;
95+
// Now process the hunk lines
96+
while (i < patchLines.length && !patchLines[i].startsWith('@@')) {
97+
const hunkLine = patchLines[i];
98+
if (hunkLine.startsWith('-')) {
99+
result.push({ old: originalLines[origIdx], new: null });
100+
origIdx++;
101+
} else if (hunkLine.startsWith('+')) {
102+
result.push({ old: null, new: modifiedLines[modIdx] });
103+
modIdx++;
104+
} else if (hunkLine.startsWith(' ')) {
105+
result.push({ old: originalLines[origIdx], new: modifiedLines[modIdx] });
106+
origIdx++;
107+
modIdx++;
108+
}
109+
i++;
102110
}
103-
diff.push({ old: null, new: line.slice(1) });
104-
newLineNumber++;
105-
} else if (line.startsWith(' ')) {
106-
diff.push({ old: line.slice(1), new: line.slice(1) });
107-
// Unchanged line, skip it
108-
oldLineNumber++;
109-
newLineNumber++;
111+
} else {
112+
i++;
110113
}
111-
});
112-
// Return the diff array
113-
return diff;
114+
}
115+
116+
// Emit any remaining unchanged lines at the end
117+
while (origIdx < originalLines.length && modIdx < modifiedLines.length) {
118+
result.push({ old: originalLines[origIdx], new: modifiedLines[modIdx] });
119+
origIdx++;
120+
modIdx++;
121+
}
122+
// If there are trailing additions or deletions
123+
while (origIdx < originalLines.length) {
124+
result.push({ old: originalLines[origIdx], new: null });
125+
origIdx++;
126+
}
127+
while (modIdx < modifiedLines.length) {
128+
result.push({ old: null, new: modifiedLines[modIdx] });
129+
modIdx++;
130+
}
131+
132+
// Only return if there are any changes
133+
const hasChanges = result.some((diff) => diff.old !== diff.new);
134+
return hasChanges ? result : [];
114135
} catch (error) {
115136
Logger.error(`Error in FileDiffUtil: ${String(error)}`);
137+
return [];
116138
}
117139
}
118140

0 commit comments

Comments
 (0)