Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions src/test/view/reviewCommentController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -595,4 +595,33 @@ 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 modifiedFileUri = toReviewUri(uri, undefined, undefined, '', false, { base: false }, repository.rootUri);
const reviewModel = new ReviewModel();
const localFileChanges = [createLocalFileChange(modifiedFileUri, 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: modifiedFileUri, lineCount: 0 } as vscode.TextDocument;
const result = await reviewCommentController.provideCommentingRanges(document, new vscode.CancellationTokenSource().token);

assert.deepStrictEqual(result, { ranges: [], enableFileComments: true });
});
});
});
8 changes: 8 additions & 0 deletions src/view/reviewCommentController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Comment thread
Copilot marked this conversation as resolved.
Resolved
}
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);
Expand Down Expand Up @@ -632,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;
Expand Down