From fcb319206aab57a2514756061acc99bccefcfc9b Mon Sep 17 00:00:00 2001 From: Uong Dong Hung Date: Sat, 28 Nov 2026 09:12:38 +0700 Subject: [PATCH 1/2] fix: allow file comments on deleted files (fixes #9207) When viewing the diff of a deleted file in a checked-out pull request, provideCommentingRanges in ReviewCommentController evaluated enableFileComments: ranges.length > 0. Because deleted files have no lines on the modified side, ranges was empty and file comments were rejected with "File comments are not allowed on this file". Return { ranges: [], enableFileComments: true } when matchedFile.status === GitChangeType.DELETE (matching the existing GitChangeType.RENAME handling) and add a regression unit test. --- src/test/view/reviewCommentController.test.ts | 32 +++++++++++++++++-- src/view/reviewCommentController.ts | 4 +++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/test/view/reviewCommentController.test.ts b/src/test/view/reviewCommentController.test.ts index 89092a7b4e..f1538cb8c0 100644 --- a/src/test/view/reviewCommentController.test.ts +++ b/src/test/view/reviewCommentController.test.ts @@ -140,12 +140,12 @@ describe('ReviewCommentController', function () { sinon.restore(); }); - function createLocalFileChange(uri: vscode.Uri, fileName: string, rootUri: vscode.Uri): GitFileChangeNode { + function createLocalFileChange(uri: vscode.Uri, fileName: string, rootUri: vscode.Uri, status: GitChangeType = GitChangeType.MODIFY): GitFileChangeNode { const gitFileChangeModel = new GitFileChangeModel( manager, activePullRequest, { - status: GitChangeType.MODIFY, + status, fileName, blobUrl: 'https://example.com', diffHunks: @@ -595,4 +595,32 @@ describe('ReviewCommentController', function () { assert.strictEqual(obsolete[fileName][1], threadB); }); }); + + describe('provideCommentingRanges', function () { + it('enables file comments for deleted files (#9207)', async function () { + const fileName = 'data/deleted.json'; + const uri = vscode.Uri.parse(`${repository.rootUri.toString()}/${fileName}`); + const reviewModel = new ReviewModel(); + const localFileChanges = [createLocalFileChange(uri, fileName, repository.rootUri, GitChangeType.DELETE)]; + reviewModel.localFileChanges = localFileChanges; + sinon.stub(manager, 'activePullRequest').get(() => activePullRequest); + sinon.stub(activePullRequest, 'isResolved').returns(true); + sinon.stub(gitApiImpl, 'repositories').get(() => [repository]); + + const reviewCommentController = new TestReviewCommentController( + reviewManager, + manager, + repository, + reviewModel, + gitApiImpl, + telemetry, + ); + context.subscriptions.push(reviewCommentController, ...localFileChanges); + + const document = { uri, lineCount: 0 } as vscode.TextDocument; + const result = await reviewCommentController.provideCommentingRanges(document, new vscode.CancellationTokenSource().token); + + assert.deepStrictEqual(result, { ranges: [], enableFileComments: true }); + }); + }); }); diff --git a/src/view/reviewCommentController.ts b/src/view/reviewCommentController.ts index a66f9e6309..e6d51866bb 100644 --- a/src/view/reviewCommentController.ts +++ b/src/view/reviewCommentController.ts @@ -535,6 +535,10 @@ export class ReviewCommentController extends CommentControllerBase implements Co const ranges: vscode.Range[] = []; if (matchedFile) { + if (matchedFile.status === GitChangeType.DELETE) { + Logger.debug('No commenting ranges: File was deleted.', ReviewCommentController.ID); + return { ranges: [], enableFileComments: true }; + } 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); From a9306d79efef2363b12694799d60ec23fe70f5b7 Mon Sep 17 00:00:00 2001 From: Uong Dong Hung Date: Sun, 29 Nov 2026 11:35:34 +0700 Subject: [PATCH 2/2] fix: match deleted-file review URIs in findMatchedFileChangeForReviewDiffView --- src/test/view/reviewCommentController.test.ts | 5 +++-- src/view/reviewCommentController.ts | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/test/view/reviewCommentController.test.ts b/src/test/view/reviewCommentController.test.ts index f1538cb8c0..a0b2fecb9e 100644 --- a/src/test/view/reviewCommentController.test.ts +++ b/src/test/view/reviewCommentController.test.ts @@ -600,8 +600,9 @@ describe('ReviewCommentController', function () { it('enables file comments for deleted files (#9207)', async function () { const fileName = 'data/deleted.json'; const uri = vscode.Uri.parse(`${repository.rootUri.toString()}/${fileName}`); + const modifiedFileUri = toReviewUri(uri, undefined, undefined, '', false, { base: false }, repository.rootUri); const reviewModel = new ReviewModel(); - const localFileChanges = [createLocalFileChange(uri, fileName, repository.rootUri, GitChangeType.DELETE)]; + const localFileChanges = [createLocalFileChange(modifiedFileUri, fileName, repository.rootUri, GitChangeType.DELETE)]; reviewModel.localFileChanges = localFileChanges; sinon.stub(manager, 'activePullRequest').get(() => activePullRequest); sinon.stub(activePullRequest, 'isResolved').returns(true); @@ -617,7 +618,7 @@ describe('ReviewCommentController', function () { ); context.subscriptions.push(reviewCommentController, ...localFileChanges); - const document = { uri, lineCount: 0 } as vscode.TextDocument; + const document = { uri: modifiedFileUri, lineCount: 0 } as vscode.TextDocument; const result = await reviewCommentController.provideCommentingRanges(document, new vscode.CancellationTokenSource().token); assert.deepStrictEqual(result, { ranges: [], enableFileComments: true }); diff --git a/src/view/reviewCommentController.ts b/src/view/reviewCommentController.ts index e6d51866bb..2b748351e6 100644 --- a/src/view/reviewCommentController.ts +++ b/src/view/reviewCommentController.ts @@ -636,6 +636,10 @@ export class ReviewCommentController extends CommentControllerBase implements Co return false; } + if (fileChange.status === GitChangeType.DELETE && fileChange.filePath.toString() === uri.toString()) { + return true; + } + if (fileChange.fileName !== query.path) { if (!((fileChange.change instanceof InMemFileChange) && fileChange.change.previousFileName === query.path)) { return false;