Skip to content

Commit 13ca123

Browse files
authored
'Not all changes could be converted to suggestions' (#6205)
Fixes #6173
1 parent 17a4a20 commit 13ca123

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/view/reviewManager.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,30 @@ export class ReviewManager {
741741
break;
742742
}
743743
}
744-
hunk.diffLines = hunk.diffLines.slice(i, j + 1);
744+
745+
let slice = hunk.diffLines.slice(i, j + 1);
746+
747+
if (slice.every(line => line.type === DiffChangeType.Add)) {
748+
// we have only inserted lines, so we need to include a context line so that
749+
// there's a line to anchor the suggestion to
750+
if (i > 1) {
751+
// include from the begginning of the hunk
752+
i--;
753+
oldLineNumber--;
754+
oldLength++;
755+
} else if (j < hunk.diffLines.length - 1) {
756+
// include from the end of the hunk
757+
j++;
758+
oldLength++;
759+
} else {
760+
// include entire context
761+
i = 1;
762+
j = hunk.diffLines.length - 1;
763+
}
764+
slice = hunk.diffLines.slice(i, j + 1);
765+
}
766+
767+
hunk.diffLines = slice;
745768
hunk.oldLength = oldLength;
746769
hunk.oldLineNumber = oldLineNumber;
747770
}

0 commit comments

Comments
 (0)