Fix file URIs using wrong workspace folder in multi-root workspaces
In multi-root workspaces, temporary file URIs for PR diffs used the first workspace folder path instead of the correct one matching the repository.
Example:
Workspace with roots A and B, viewing PR from repo B:
- Expected: vscode-userdata:/.../temp/B/file.png
- Actual: vscode-userdata:/.../temp/A/file.png ❌
Changes
-
src/common/uri.ts: Passrepository.rootUritoTemporaryState.write()inasTempStorageURI() -
src/common/temporaryState.ts:- Add optional
repositoryUriparameter towriteState()andwrite() - Match workspace folder by comparing URIs instead of always using first folder
- Fall back to first folder if no match (preserves single-root behavior)
- Add optional
Original prompt
This section details on the original issue you should resolve
<issue_title>Wrong file URIs with multiple roots</issue_title> <issue_description>Type: Bug
File URIs are wrong when you have a multiple root workspace.
For example: I have a workspace with roots A an B and a PR for root B
- A (master)
- B (PR branch)
When I open a file from the PR branch the
vscode-userdataURI for the non-local file contains the path with root A.URIs of both files in diff view:
file:///home/username/B/file.pngvscode-userdata:/home/username/.config/Code/User/globalStorage/github.vscode-pull-request-github/temp/A/filename.pngI'd expect the
vscode-userdatafile to have B in the root path instead of A:
vscode-userdata:/home/username/.config/Code/User/globalStorage/github.vscode-pull-request-github/temp/B/filename.pngI've only checked with image files, but I assume this could happen with other files as well.
Extension version: 0.94.0 VS Code version: Code 1.92.2 (fee1edb8d6d72a0ddff41e5f71a671c23ed924b9, 2024-08-14T17:29:30.058Z) OS version: Linux x64 5.14.0-1048-oem Modes:
Comments on the Issue (you are @copilot in this section)
- Fixes microsoft/vscode-pull-request-github#6156
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.