From 1db896c49fb56bcebf2b8bc8d50893ea7ff36bfd Mon Sep 17 00:00:00 2001 From: Anurag Maherchandani Date: Fri, 21 Mar 2025 10:24:50 +0530 Subject: [PATCH] fixing the error --- src/main.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 2fdb3eb..01abe4f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -171,10 +171,28 @@ function createComment( if (!file.to) { return []; } + + // Convert AI provided line number to a number + const lineNumber = Number(aiResponse.lineNumber); + + // Check if the line number is actually in the diff + const isLineInDiff = chunk.changes.some(change => + // For new lines (addition) + (change.type === 'add' && change.ln === lineNumber) || + // For context and deleted lines + (change.ln2 === lineNumber) + ); + + // Only return comments for lines that are in the diff + if (!isLineInDiff) { + console.log(`Skipping comment for ${file.to}:${lineNumber} as it's not part of the diff`); + return []; + } + return { body: aiResponse.reviewComment, path: file.to, - line: Number(aiResponse.lineNumber), + line: lineNumber, }; }); }