From 13ca123f401c339f11a405fde4b107dd0e58cd64 Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Tue, 3 Sep 2024 15:25:36 +0200 Subject: [PATCH] 'Not all changes could be converted to suggestions' (#6205) Fixes #6173 --- src/view/reviewManager.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/view/reviewManager.ts b/src/view/reviewManager.ts index 267b105a09..5882759ea0 100644 --- a/src/view/reviewManager.ts +++ b/src/view/reviewManager.ts @@ -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; }