Fix commenting on added files in the Commits tree - #8866
Fix commenting on added files in the Commits tree#8866artur-czuba-iyuno wants to merge 1 commit into
Conversation
When a file added by a commit is opened from the Commits node, the right-hand side of the diff is given `parentFilePath`, which is a `review` uri with `base: true`. `ReviewCommentController.provideCommentingRanges` then calls `getCommentingRanges(hunks, isBase: true)`, which builds ranges only from `Delete` diff lines. An added file has none, so no commenting ranges are produced and the `+` never appears in the gutter. Use `filePath` for the head side instead. The `DELETE` case is left as it is: the content of a deleted file lives on the base side, and so does the comment. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
@artur-czuba-iyuno please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
There was a problem hiding this comment.
Pull request overview
This PR fixes commenting support when opening diffs for added files from the Commits tree by ensuring the head-side document URI is used, allowing ReviewCommentController.provideCommentingRanges to generate valid commenting ranges.
Changes:
- Use
changeModel.filePath(head side) instead ofchangeModel.parentFilePath(base side) when diffing added files from the Commits tree. - Add unit tests to verify added files use the head-side URI and deleted files continue to use the base-side URI.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/view/treeNodes/fileChangeNode.ts |
Adjusts the vscode.diff arguments for added files so commenting ranges are computed on the correct (head) side. |
src/test/view/treeNodes/gitFileChangeNode.test.ts |
Adds coverage for the added vs deleted file diff-URI behavior in the Commits tree. |
Comments suppressed due to low confidence (1)
src/test/view/treeNodes/gitFileChangeNode.test.ts:88
- Same as above:
vscode.diffcommand arguments include non-URI values after the first two entries, soas vscode.Uri[]is misleading. Use a tuple type to capture the expected shape.
const [left, right] = node.command.arguments as vscode.Uri[];
| await node.resolve(); | ||
|
|
||
| assert.strictEqual(node.command.command, 'vscode.diff'); | ||
| const [left, right] = node.command.arguments as vscode.Uri[]; |
When a file added by a commit is opened from the Commits node, the right-hand side of the diff is given
parentFilePath— areviewURI withbase: true.ReviewCommentController.provideCommentingRangesthen callsgetCommentingRanges(hunks, isBase: true), which builds ranges only fromDeletediff lines. An added file has none, so no commenting ranges are produced and the+never appears in the gutter. The extension log shows:The head side of the diff should use
filePathinstead. TheDELETEcase is left as it is: the content of a deleted file lives on the base side, and so does the comment.This has been the behavior since #2334, so it is not a recent regression.
Testing
New
src/test/view/treeNodes/gitFileChangeNode.test.tscovers both branches — that an added file is diffed against the head side, and that a deleted file keeps using the base side.Verified manually against a checked out pull request: added files under a commit in the Commits tree now offer the
+in the gutter and accept a comment.Note
I have a second change that builds on this one, for commenting on files from earlier commits of a pull request (refs #4315). Keeping it separate since this fix stands on its own.