feat: add support for VSCode file encodings #11042
Draft
+542
−7
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.
Related GitHub Issue
Closes: #11002
Description
This PR attempts to address Issue #11002 by adding support for VSCode file encodings.
Problem: Roo Code previously hardcoded UTF-8 encoding for all file read/write operations. When editing files with non-UTF-8 encodings (like CP 852), the content was read as UTF-8, modified, and written back as UTF-8, which corrupted special characters (e.g., č, ć, ž, š, đ).
Solution: This PR implements encoding detection and preservation:
New encoding utility (
src/utils/fileEncoding.ts):files.encoding)readFileWithEncoding()andwriteFileWithEncoding()functionsModified
DiffViewProvider.ts:Modified
ApplyPatchTool.ts:Added
iconv-litedependency:Test Procedure
cd src && npx vitest run utils/__tests__/fileEncoding.spec.ts- all 17 tests pass"files.encoding": "cp852"for a workspacePre-Submission Checklist
Screenshots / Videos
N/A - No UI changes, this is a backend encoding fix.
Documentation Updates
files.encodingsetting.Additional Notes
This implementation follows the user's requested approach from the issue discussion:
Feedback and guidance are welcome!
Important
Adds support for VSCode file encodings, enabling encoding-aware file operations and fallback to UTF-8 if conversion fails.
readFileWithEncoding()andwriteFileWithEncoding()infileEncoding.tsto handle file encodings based on VSCode settings.DiffViewProvider.tsto use encoding-aware reading and writing for file operations.ApplyPatchTool.tsto use encoding-aware reading and writing for patch operations.iconv-litetopackage.jsonfor encoding conversion support.fileEncoding.spec.tsto verify encoding handling and fallback behavior.This description was created by
for 57f07a8. You can customize this summary. It will automatically update as commits are pushed.