Accepted Encoding
A Visual Studio Code extension that alerts when the encoding of an open file does not match the defined configuration.
Features
- Automatic encoding mismatch detection: Monitors open files and detects when their actual encoding does not match the expected configuration
- Visual status bar indicator: Displays an alert indicator in the VS Code status bar when a mismatch is detected
- Configurable warning messages: Shows alert notifications with details about the expected vs. actual encoding
Installation
- Open VS Code
- Go to the Extensions view (
Ctrl+Shift+X / Cmd+Shift+X)
- Search for "Accepted Encodings"
- Click Install
Usage
Once installed, the extension works automatically. When you open a file whose encoding does not match your files.encoding configuration:
- An alert indicator will appear in the status bar (if enabled)
- You will receive a warning notification with details and conversion options (if enabled)
- You can check encoding anytime with the context menu item "Check Encoding Mismatch"
Choosing one of the "Open as ..." options behaves differently depending on whether the file has a BOM (Byte Order Mark):
- File has a BOM (i.e. the detected encoding was UTF-8 with BOM, UTF-16 LE, or UTF-16 BE): you'll be asked "Do you want to convert the file to the selected encoding?" first.
- Yes — the file is actually converted on disk (bytes rewritten, BOM added/removed as needed) and reopened. This is required for the change to stick, since VS Code always re-detects encoding from a file's BOM on a fresh open.
- No — the file is simply reopened asking VS Code to interpret it with the selected encoding, without touching the file on disk. Note that for BOM files this may not "stick" on a later reopen, and the warning could reappear.
- File has no BOM: it's reopened directly with the selected encoding, without touching the file on disk and without any prompt.
Example
If your configuration expects UTF-8 but you open a file with windows-1252 encoding:
Encoding mismatch in "file.txt": expected "utf8" but found "windows1252"
Configuration
The extension provides the following configuration options in settings.json:
AcceptedEncodings.show_message_box
- Type:
boolean
- Default:
true
- Description: Show warning messages when file encoding doesn't match the configured encoding
{
"AcceptedEncodings.showErrorMessages": true
}
AcceptedEncodings.show_status_bar
- Type:
boolean
- Default:
true
- Description: Show a status bar indicator when encoding mismatch is detected
{
"AcceptedEncodings.show_status_bar": true
}
AcceptedEncodings.accepted_encodings
- Type:
array
- Default:
["utf8", "utf8bom", "iso88597"]
- Description: Select which encodings are accepted, from a checkbox list of all VS Code-supported encodings, in the Settings UI (or edit the array directly in
settings.json)
{
"AcceptedEncodings.accepted_encodings": ["utf8", "utf8bom", "iso88597"]
}
Feedback and Contributions
Feature suggestions and contributions are welcome. You can:
- Report issues
- Suggest new features
- Submit pull requests with improvements
Enjoying the extension? Consider leaving a review or starring the repository.