Skip to content

Fix: Handle binary files (images) in diff views for newly added files#14

Draft
Copilot wants to merge 3 commits into
masterfrom
copilot/fix-diff-view-error
Draft

Fix: Handle binary files (images) in diff views for newly added files#14
Copilot wants to merge 3 commits into
masterfrom
copilot/fix-diff-view-error

Conversation

Copilot AI commented Oct 21, 2025

Copy link
Copy Markdown

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_SCHEME was using a TextDocumentContentProvider, 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 TextDocumentContentProvider with a proper FileSystemProvider implementation that supports both text and binary files:

  • Created EmptyFileSystemProvider - A new class implementing the vscode.FileSystemProvider interface
  • Binary-safe content handling - The readFile() method returns Uint8Array(0) (an empty binary buffer), which works for both text and binary files
  • Updated provider registration - Changed from registerTextDocumentContentProvider to registerFileSystemProvider

Technical Details

The key difference is:

  • TextDocumentContentProvider.provideTextDocumentContent() returns a string - only suitable for text
  • FileSystemProvider.readFile() returns Uint8Array - works for both text and binary content

When a file is added (status = FileChangeStatus.Added), the code in changes/files.ts sets baseFileUri = emptyFileUri. With this fix, the empty file is now properly handled by the new EmptyFileSystemProvider, enabling correct diff display for newly added images.

Changes

  • Modified extensions/github1s/src/providers/index.ts:
    • Added EmptyFileSystemProvider class implementing FileSystemProvider
    • Replaced text-based provider registration with file system provider
    • Added /empty path to emptyFileUri for proper file system handling

Fixes the issue described in: "当有新增图片时,在diff视图报错" (Error in diff view when there are new images)

Original prompt

This section details on the original issue you should resolve

<issue_title>当有新增图片时,在diff视图报错</issue_title>
<issue_description>应该一侧展示为空,另一侧展示图片</issue_description>

Comments on the Issue (you are @copilot in this section)

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.

wolfsilver and others added 2 commits October 3, 2025 08:19
chore(deps-dev): bump cipher-base in /extensions/github1s (conwnet#639)
Co-authored-by: wolfsilver <2452450+wolfsilver@users.noreply.github.com>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying github1s with  Cloudflare Pages  Cloudflare Pages

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

View logs

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
Copilot AI requested a review from wolfsilver October 21, 2025 08:39
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.

当有新增图片时,在diff视图报错

2 participants