Skip to content

Fix commenting on added files in the Commits tree - #8866

Closed
Artur Czuba (artur-czuba-iyuno) wants to merge 1 commit into
microsoft:mainfrom
artur-czuba-iyuno:fix-comment-added-file-commit-diff
Closed

Artur Czuba (artur-czuba-iyuno) wants to merge 1 commit into
microsoft:mainfrom
artur-czuba-iyuno:fix-comment-added-file-commit-diff

Conversation

@artur-czuba-iyuno

Copy link
Copy Markdown

When a file added by a commit is opened from the Commits node, the right-hand side of the diff is given parentFilePath — 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. The extension log shows:

No commenting ranges: Diff is in base and none of the diff hunks could be added.

The head side of the diff should use filePath 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.

This has been the behavior since #2334, so it is not a recent regression.

Testing

New src/test/view/treeNodes/gitFileChangeNode.test.ts covers 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.

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>

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.

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 of changeModel.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.diff command arguments include non-URI values after the first two entries, so as 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[];
@artur-czuba-iyuno Artur Czuba (artur-czuba-iyuno) closed this by deleting the head repository Oct 7, 2026
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.

2 participants