Fix: Handle binary files (images) in diff views for newly added files#14
Draft
Copilot wants to merge 3 commits into
Draft
Fix: Handle binary files (images) in diff views for newly added files#14Copilot wants to merge 3 commits into
Copilot wants to merge 3 commits into
Conversation
chore(deps-dev): bump cipher-base in /extensions/github1s (conwnet#639)
Co-authored-by: wolfsilver <2452450+wolfsilver@users.noreply.github.com>
Deploying github1s with
|
| Latest commit: |
81df47c
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://66338d9e.github1s-bzn.pages.dev |
| Branch Preview URL: | https://copilot-fix-diff-view-error.github1s-bzn.pages.dev |
Copilot
AI
changed the title
[WIP] Fix error in diff view for new images
Fix: Handle binary files (images) in diff views for newly added files
Oct 21, 2025
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.
Problem
When viewing a diff of a newly added image file, the application throws an error instead of properly displaying the image on one side and an empty side on the other.
This issue occurs because the
EMPTY_FILE_SCHEMEwas using aTextDocumentContentProvider, which is designed only for text documents. When VS Code attempts to render a diff with a binary file (such as an image) on one side and an empty file on the other, the text-based provider cannot handle the binary content, resulting in an error.Solution
Replaced the
TextDocumentContentProviderwith a properFileSystemProviderimplementation that supports both text and binary files:EmptyFileSystemProvider- A new class implementing thevscode.FileSystemProviderinterfacereadFile()method returnsUint8Array(0)(an empty binary buffer), which works for both text and binary filesregisterTextDocumentContentProvidertoregisterFileSystemProviderTechnical Details
The key difference is:
TextDocumentContentProvider.provideTextDocumentContent()returns astring- only suitable for textFileSystemProvider.readFile()returnsUint8Array- works for both text and binary contentWhen a file is added (status =
FileChangeStatus.Added), the code inchanges/files.tssetsbaseFileUri = emptyFileUri. With this fix, the empty file is now properly handled by the newEmptyFileSystemProvider, enabling correct diff display for newly added images.Changes
extensions/github1s/src/providers/index.ts:EmptyFileSystemProviderclass implementingFileSystemProvider/emptypath toemptyFileUrifor proper file system handlingFixes the issue described in: "当有新增图片时,在diff视图报错" (Error in diff view when there are new images)
Original prompt
Fixes #13
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.