Fix file changes URI generation for multi-file changes in pull requests #1593
+43
−6
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.
Problem
The
PullRequestFileChangesServicewas not properly generating URIs for different file change types when creating multi-diff views for pull requests. The previous implementation always set bothoriginalUriandmodifiedUrito valid file paths, which violated theChatResponseDiffEntryAPI specification and resulted in incorrect visual representation of added and deleted files.According to the VS Code
ChatResponseDiffEntryinterface:originalUriset toundefined(no original version exists)modifiedUriset toundefined(no modified version exists)The previous implementation treated all file types the same way, causing the multi-diff view to display incorrect diff information for these special cases.
Solution
Updated
pullRequestFileChangesService.tsto properly handle all GitHub PR file status types using an explicit switch statement:added: Sets onlymodifiedUri(new file location), leavesoriginalUriasundefinedremoved: Sets onlyoriginalUri(deleted file location), leavesmodifiedUriasundefinedrenamed: SetsoriginalUrito old filename (fromprevious_filename) andmodifiedUrito new filenamemodified/changed: Sets both URIs to the same file path (standard diff)copied: SetsoriginalUrito source file andmodifiedUrito target file (usingprevious_filename)Example
For a PR with an added file:
Before:
After:
Benefits
ChatResponseDiffEntryinterface specificationTesting
Original prompt
Created from VS Code via the GitHub Pull Request extension.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.