Skip to content

Commit b4aae3f

Browse files
authored
fix(amazonq): edit diff UI doesnt render correctly when the diff contains only space char or empty line (#7922)
## Problem The suggestion indicates the empty line (L4) is edited and replaced with suggestion content however there is no diff highlight. Reason behind is because the function `diffWordsWithSpace` will not say the line is removed (since it's be edited). https://github.com/aws/aws-toolkit-vscode/blob/master/packages/amazonq/src/app/inline/EditRendering/svgGenerator.ts#L437-L441 <img width="1299" height="1292" alt="image" src="https://github.com/user-attachments/assets/a2a07ba0-28fe-4f31-9b8a-37d5ef2ff223" /> ## Solution <img width="1299" height="1292" alt="image" src="https://github.com/user-attachments/assets/a8530917-ac06-4b9e-af39-ea037c38b340" /> --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent be505ec commit b4aae3f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

packages/amazonq/src/app/inline/EditRendering/svgGenerator.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export const emptyDiffSvg = {
1818
originalCodeHighlightRange: [],
1919
}
2020

21+
const defaultLineHighlightLength = 4
22+
2123
export class SvgGenerationService {
2224
/**
2325
* Generates an SVG image representing a code diff
@@ -431,8 +433,12 @@ export class SvgGenerationService {
431433
for (let lineIndex = 0; lineIndex < originalCode.length; lineIndex++) {
432434
const line = originalCode[lineIndex]
433435

436+
/**
437+
* If [line] is an empty line or only contains whitespace char, [diffWordsWithSpace] will say it's not an "remove", i.e. [part.removed] will be undefined,
438+
* therefore the deletion will not be highlighted. Thus fallback this scenario to highlight the entire line
439+
*/
434440
// If line exists in modifiedLines as a key, process character diffs
435-
if (Array.from(modifiedLines.keys()).includes(line)) {
441+
if (Array.from(modifiedLines.keys()).includes(line) && line.trim().length > 0) {
436442
const modifiedLine = modifiedLines.get(line)!
437443
const changes = diffWordsWithSpace(line, modifiedLine)
438444

@@ -455,7 +461,7 @@ export class SvgGenerationService {
455461
originalRanges.push({
456462
line: lineIndex,
457463
start: 0,
458-
end: line.length,
464+
end: line.length ?? defaultLineHighlightLength,
459465
})
460466
}
461467
}

0 commit comments

Comments
 (0)