Support review comments in the per-commit diff view#8648
Open
daandemeyer wants to merge 1 commit intomicrosoft:mainfrom
Open
Support review comments in the per-commit diff view#8648daandemeyer wants to merge 1 commit intomicrosoft:mainfrom
daandemeyer wants to merge 1 commit intomicrosoft:mainfrom
Conversation
Until now, opening a file diff from the commits tree of a PR showed no
commenting UI and no existing review comments — commenting only worked
from the changed-files tree. This change adds full commenting support
to the per-commit diff view, anchoring new comments to the commit
being viewed.
Display side
------------
- Add a fourth thread map `_commitFileChangeCommentThreads`, keyed by
`${path}@${originalCommitId}` so multiple commits' threads on the
same file don't collide.
- For every non-outdated thread with a known `originalCommitId`,
mirror it on a per-commit `review://...?commit=...&isOutdated=true`
URI that matches the one `CommitNode` produces, in addition to its
existing workspace/review-scheme entry.
- Consolidate `createOutdatedCommentThread` with the new commit-scoped
variant into a single `createCommitAnchoredCommentThread` (the URI
shape is identical — only the call sites differ).
- Replace `_findMatchingThread` with `_findMatchingThreads` /
`_removeMatchingThreads` so changed/removed thread events update or
dispose both the workspace/review mirror and the commit-scoped one.
- `provideCommentingRanges` falls back to fetching the commit's patch
via a new `PullRequestModel.getCommitFileDiffHunks` helper when
`findMatchedFileChangeForReviewDiffView` returns no match (because
commit-scoped URIs aren't in `localFileChanges`, which only tracks
the PR head).
- Wire the new map into `onDidChangePendingReviewState` and simplify
`updateCommentExpandState` to iterate all four maps via a shared
helper.
Write side
----------
- `PullRequestModel.createReviewThread` takes a new optional
`commitId` parameter. When `commitId !== HEAD`, the model routes
through a new private `createReviewThreadOnCommit` helper that uses
the (deprecated but still-functional) `addPullRequestReviewComment`
GraphQL mutation with explicit `commitOID`. This is necessary
because `addPullRequestReviewThread` always anchors new threads to
the PR head regardless of which commit the pending review was
created on, so the deprecated path is the only way to anchor a new
comment to a non-head commit. After the mutation, the threads cache
is refreshed via `getReviewThreads()` so the new thread propagates
through the existing `onDidChangeReviewThreads` pipeline.
- The deprecated mutation only accepts a single integer `position`
(the diff offset from the first hunk header), not line/side ranges,
so a new `computeDiffPositionForLine` helper walks the commit's diff
hunks to map a line number to a position. Multi-line ranges collapse
to a single line at `endLine` in this fallback path.
- New controller helpers `getFileNameForThread`, `getCommitForThread`
and `getCommentLinesForThread` extract path, commit and line numbers
from any thread URI. Crucially, for commit-scoped review URIs the
filename comes from `query.path` rather than
`gitRelativeRootPath(uri.path)`, since `CommitNode` builds URIs via
`reviewPath()` which produces a synthetic `commit~ec597364/foo/bar`
prefix that `nodePath.relative` turns into garbage. Editor line
numbers for review-scheme URIs are used directly (no mapping
through workspace diffs), since they already match the file at the
ref being viewed.
- `startReview` (the controller method) and `createOrReplyComment`
now forward `getCommitForThread(thread)` for both new threads and
replies, so replying to a comment in a non-head commit's diff lands
on the right commit too.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Until now, opening a file diff from the commits tree of a PR showed no commenting UI and no existing review comments — commenting only worked from the changed-files tree. This change adds full commenting support to the per-commit diff view, anchoring new comments to the commit being viewed.
Display side
_commitFileChangeCommentThreads, keyed by${path}@${originalCommitId}so multiple commits' threads on the same file don't collide.originalCommitId, mirror it on a per-commitreview://...?commit=...&isOutdated=trueURI that matches the oneCommitNodeproduces, in addition to its existing workspace/review-scheme entry.createOutdatedCommentThreadwith the new commit-scoped variant into a singlecreateCommitAnchoredCommentThread(the URI shape is identical — only the call sites differ)._findMatchingThreadwith_findMatchingThreads/_removeMatchingThreadsso changed/removed thread events update or dispose both the workspace/review mirror and the commit-scoped one.provideCommentingRangesfalls back to fetching the commit's patch via a newPullRequestModel.getCommitFileDiffHunkshelper whenfindMatchedFileChangeForReviewDiffViewreturns no match (because commit-scoped URIs aren't inlocalFileChanges, which only tracks the PR head).onDidChangePendingReviewStateand simplifyupdateCommentExpandStateto iterate all four maps via a shared helper.Write side
PullRequestModel.createReviewThreadtakes a new optionalcommitIdparameter. WhencommitId !== HEAD, the model routes through a new privatecreateReviewThreadOnCommithelper that uses the (deprecated but still-functional)addPullRequestReviewCommentGraphQL mutation with explicitcommitOID. This is necessary becauseaddPullRequestReviewThreadalways anchors new threads to the PR head regardless of which commit the pending review was created on, so the deprecated path is the only way to anchor a new comment to a non-head commit. After the mutation, the threads cache is refreshed viagetReviewThreads()so the new thread propagates through the existingonDidChangeReviewThreadspipeline.position(the diff offset from the first hunk header), not line/side ranges, so a newcomputeDiffPositionForLinehelper walks the commit's diff hunks to map a line number to a position. Multi-line ranges collapse to a single line atendLinein this fallback path.getFileNameForThread,getCommitForThreadandgetCommentLinesForThreadextract path, commit and line numbers from any thread URI. Crucially, for commit-scoped review URIs the filename comes fromquery.pathrather thangitRelativeRootPath(uri.path), sinceCommitNodebuilds URIs viareviewPath()which produces a syntheticcommit~ec597364/foo/barprefix thatnodePath.relativeturns into garbage. Editor line numbers for review-scheme URIs are used directly (no mapping through workspace diffs), since they already match the file at the ref being viewed.startReview(the controller method) andcreateOrReplyCommentnow forwardgetCommitForThread(thread)for both new threads and replies, so replying to a comment in a non-head commit's diff lands on the right commit too.