Skip to content

fix: allow file comments on deleted files (fixes #9207) - #9239

Open
Uong Dong Hung (hungud) wants to merge 2 commits into
microsoft:mainfrom
hungud:fix/9207-deleted-file-comment
Open

Uong Dong Hung (hungud) wants to merge 2 commits into
microsoft:mainfrom
hungud:fix/9207-deleted-file-comment

Conversation

@hungud

Copy link
Copy Markdown
Contributor

Fixes #9207

Problem

When checking out a pull request and clicking Add File Comment on a deleted file's diff, VS Code showed "File comments are not allowed on this file." even though line comments on the deleted lines still worked.

In ReviewCommentController.provideCommentingRanges (src/view/reviewCommentController.ts), the local-repository branch returned enableFileComments: ranges.length > 0. Since a deleted file has no new lines on the modified side, ranges was empty ([]) and enableFileComments evaluated to false.

Changes

  • Handle GitChangeType.DELETE in ReviewCommentController.provideCommentingRanges by returning { ranges: [], enableFileComments: true }, consistent with the existing GitChangeType.RENAME handling.
  • Added a unit test in src/test/view/reviewCommentController.test.ts verifying enableFileComments: true for deleted files.

Verification & QA Proof

  • Ran npx tsc -p tsconfig.json --noEmit and npx tsc -p tsconfig.test.json --noEmit with zero errors.

Before Fix (Red Test & VS Code Error)

Red Test Reproduced
VS Code UI Red

After Fix (Green Test & VS Code File Comment Enabled)

Green Test Passed
VS Code UI Green

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.
Copilot AI balanced review requested due to automatic review settings November 28, 2026 02:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Deleted-file diffs opened from Files changed still leave Add File Comment disabled because their review URIs are not handled, and the regression test does not use the actual URI construction.

1 open issue
What changed in this PR

This PR aims to fix #9207 by allowing file-level comments on deleted files in checked-out pull requests.

Changes:

  • Enables file comments for deletions in the local-repository commenting-range branch.
  • Adds a regression test and allows the test helper to create file changes with different statuses.
File Description
src/​view/​reviewCommentController.ts Adds a deletion-specific return enabling file comments without line ranges.
src/​test/​view/​reviewCommentController.test.ts Parameterizes the helper’s change status and tests file-comment availability for deletions.

Review effort: Balanced

Comment thread src/view/reviewCommentController.ts Resolved
Copilot AI balanced review requested due to automatic review settings November 29, 2026 04:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the change enabling file-level comments on deleted files.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot create a file comment on a file deleted in PR

3 participants