From 9dba942a27d8bca2b48a76b96d30010f4d14421b Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Fri, 13 Dec 2024 16:42:08 +0100 Subject: [PATCH] error when adding file comment to renamed file w/o other changes (#6538) Fixes #6516 --- src/view/reviewCommentController.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/view/reviewCommentController.ts b/src/view/reviewCommentController.ts index b9e4b6e265..e44c1bd891 100644 --- a/src/view/reviewCommentController.ts +++ b/src/view/reviewCommentController.ts @@ -13,7 +13,7 @@ import { DiffSide, IReviewThread, SubjectType } from '../common/comment'; import { getCommentingRanges } from '../common/commentingRanges'; import { mapNewPositionToOld, mapOldPositionToNew } from '../common/diffPositionMapping'; import { commands, contexts } from '../common/executeCommands'; -import { GitChangeType } from '../common/file'; +import { GitChangeType, InMemFileChange } from '../common/file'; import { disposeAll } from '../common/lifecycle'; import Logger from '../common/logger'; import { PR_SETTINGS_NAMESPACE, PULL_BRANCH, PULL_PR_BRANCH_BEFORE_CHECKOUT, PullPRBranchVariants } from '../common/settingKeys'; @@ -504,7 +504,7 @@ export class ReviewCommentController extends CommentControllerBase implements Co const diffHunks = await matchedFile.changeModel.diffHunks(); if ((matchedFile.status === GitChangeType.RENAME) && (diffHunks.length === 0)) { Logger.debug('No commenting ranges: File was renamed with no diffs.', ReviewCommentController.ID); - return; + return { ranges: [], enableFileComments: true }; } const contentDiff = await this.getContentDiff(document.uri, matchedFile.fileName); @@ -599,7 +599,9 @@ export class ReviewCommentController extends CommentControllerBase implements Co } if (fileChange.fileName !== query.path) { - return false; + if (!((fileChange.change instanceof InMemFileChange) && fileChange.change.previousFileName === query.path)) { + return false; + } } if (fileChange.filePath.scheme !== 'review') {