Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support setting encoding per file #237828

Open
awvalenti opened this issue Jan 13, 2025 · 5 comments
Open

Support setting encoding per file #237828

awvalenti opened this issue Jan 13, 2025 · 5 comments
Labels
feature-request Request for new features or functionality file-encoding File encoding type issues

Comments

@awvalenti
Copy link

awvalenti commented Jan 13, 2025

files.encoding allows setting encoding user-wide or workspace-wide. Sometimes we need to set different encodings for specific files. I'd like something like:

{
  "files.encoding": "iso88591",
  "file-specific": {
    "/src/my-file.md": {
      "files.encoding": "utf8"
    }
  }
}

(EDITED: adding the missing second files.encoding part)

Actual situation: my project uses iso88591. I'm using marp and need to save only that markdown file in utf8.

@bpasero
Copy link
Member

bpasero commented Jan 13, 2025

I think there should rather be general support to scope a setting to a resource. Related #35350

@bpasero bpasero added feature-request Request for new features or functionality file-encoding File encoding type issues labels Jan 13, 2025
@bpasero bpasero removed their assignment Jan 13, 2025
@vs-code-engineering vs-code-engineering bot added this to the Backlog Candidates milestone Jan 13, 2025
Copy link

This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

@ped7g
Copy link

ped7g commented Jan 20, 2025

OP: I assume you are aware you can reopen the file with different encoding in the VSC and then it somehow does remember the specific encoding for that particular file as far as I can tell. But I'm unable to tell where that setting is stored, doesn't modify any of the settings.json files, so it must be elsewhere? So your issue is asking to move this into settings? (asking just to clarify it to myself - confused user of VSC, nothing more significant, sry :) )

I do see some value in having this pre-set in git repo file, so any newly cloned repo will behave correctly without manually reopening the file.

@awvalenti
Copy link
Author

It remembers that choice only while the editor is open. If you close it and reopen, it resorts again to workspace setting. It's problably on some very temporary config file, i.e., too fragile.

Image

@yhatt
Copy link
Contributor

yhatt commented Jan 20, 2025

files.encoding is just setting for the default character set. An actually selected encoding by UI may become different from that setting. It has stored to the memory of each text editing area, and currently it seems to be able to access that only by VS Code internally.

function toEditorWithEncodingSupport(input: EditorInput): IEncodingSupport | null {

Actual situation: my project uses iso88591. I'm using marp and need to save only that markdown file in utf8.

I'm the author of Marp it mentioned at here. The original issue was recieved at marp-team/marp#558, as an possibility issue report for the Marp for VS Code extension.

If VS Code extensions can access to the current encoding for each text editor, the original issue by the reporter would be solved because the extension can do proper conditional branching by the selected character set. So if provided a solution against the long-standing issue #824, this proposal might not be needed from the standpoint of reporter. (e.g. PR #177434)

Our extension might implement heuristic based on the current files.encoding setting and might avoid the problem due to uncommon encoding, but it is not accurate because the actually preferred character set in the document may not same as files.encoding.

Similar?: #209503, microsoft/vscode-cpptools#13047

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality file-encoding File encoding type issues
Projects
None yet
Development

No branches or pull requests

4 participants