Skip to content

Commit

Permalink
'Not all changes could be converted to suggestions' (#6205)
Browse files Browse the repository at this point in the history
Fixes #6173
  • Loading branch information
alexr00 authored Sep 3, 2024
1 parent 17a4a20 commit 13ca123
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/view/reviewManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,30 @@ export class ReviewManager {
break;
}
}
hunk.diffLines = hunk.diffLines.slice(i, j + 1);

let slice = hunk.diffLines.slice(i, j + 1);

if (slice.every(line => line.type === DiffChangeType.Add)) {
// we have only inserted lines, so we need to include a context line so that
// there's a line to anchor the suggestion to
if (i > 1) {
// include from the begginning of the hunk
i--;
oldLineNumber--;
oldLength++;
} else if (j < hunk.diffLines.length - 1) {
// include from the end of the hunk
j++;
oldLength++;
} else {
// include entire context
i = 1;
j = hunk.diffLines.length - 1;
}
slice = hunk.diffLines.slice(i, j + 1);
}

hunk.diffLines = slice;
hunk.oldLength = oldLength;
hunk.oldLineNumber = oldLineNumber;
}
Expand Down

0 comments on commit 13ca123

Please sign in to comment.