Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Jan 28, 2026

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:

  1. New encoding utility (src/utils/fileEncoding.ts):

    • Gets the file encoding from VSCode settings (files.encoding)
    • Provides readFileWithEncoding() and writeFileWithEncoding() functions
    • Converts content to UTF-8 internally for AI processing
    • Converts back to original encoding when saving
    • Includes fallback to UTF-8 if encoding conversion fails (with console warning)
  2. Modified DiffViewProvider.ts:

    • Uses encoding-aware reading when opening files
    • Uses encoding-aware writing when saving files directly
  3. Modified ApplyPatchTool.ts:

    • Uses encoding-aware reading for patch operations
    • Uses encoding-aware writing for file moves
  4. Added iconv-lite dependency:

    • Popular, well-tested library for encoding conversion in Node.js
    • Supports a wide range of encodings including CP 852

Test Procedure

  1. Unit tests: Run cd src && npx vitest run utils/__tests__/fileEncoding.spec.ts - all 17 tests pass
  2. Manual testing:
    • Configure VSCode with "files.encoding": "cp852" for a workspace
    • Open a file with CP 852 characters (č, ć, ž, š, đ)
    • Make edits using Roo Code
    • Verify the file is saved with CP 852 encoding and characters are preserved

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

N/A - No UI changes, this is a backend encoding fix.

Documentation Updates

  • No documentation updates are required.
  • Yes, documentation updates may be useful to explain that Roo Code now respects VSCode's files.encoding setting.

Additional Notes

This implementation follows the user's requested approach from the issue discussion:

  1. Relies on VSCode file encodings (not automatic detection)
  2. Includes fallback to UTF-8 with console warning if encoding conversion fails
  3. No special file patterns or workspace settings needed

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.

  • Behavior:
    • Adds readFileWithEncoding() and writeFileWithEncoding() in fileEncoding.ts to handle file encodings based on VSCode settings.
    • Falls back to UTF-8 with a warning if encoding conversion fails.
  • Integration:
    • Updates DiffViewProvider.ts to use encoding-aware reading and writing for file operations.
    • Updates ApplyPatchTool.ts to use encoding-aware reading and writing for patch operations.
  • Dependencies:
    • Adds iconv-lite to package.json for encoding conversion support.
  • Testing:
    • Adds unit tests in fileEncoding.spec.ts to verify encoding handling and fallback behavior.

This description was created by Ellipsis for 57f07a8. You can customize this summary. It will automatically update as commits are pushed.

- Add iconv-lite dependency for encoding conversion
- Create src/utils/fileEncoding.ts utility that:
  - Gets file encoding from VSCode settings (files.encoding)
  - Provides readFileWithEncoding() and writeFileWithEncoding() functions
  - Includes fallback to UTF-8 if encoding conversion fails
- Update DiffViewProvider.ts to use encoding-aware file operations
- Update ApplyPatchTool.ts to use encoding-aware file operations
- Add comprehensive tests for the encoding utility

Fixes #11002
@roomote
Copy link
Contributor Author

roomote bot commented Jan 28, 2026

Rooviewer Clock   See task on Roo Cloud

Review completed. No issues found.

The implementation correctly adds encoding support for VSCode's files.encoding setting. The new fileEncoding.ts utility properly reads/writes files with the configured encoding and includes robust fallback handling. The integration with DiffViewProvider.ts and ApplyPatchTool.ts is correct. Tests are comprehensive.

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

Legacy encoding [BUG]

1 participant