-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Provide encoding-related APIs for editor extensions #824
Comments
👍 Also |
This comment was marked as resolved.
This comment was marked as resolved.
|
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
I also need this for my extension, as I explain here. Did not realize this issue already existed. Definitely want this feature! |
I believe that full |
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
3 similar comments
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This feature was first requested back in 2015 when VSCode was just emerging from the primordial ooze. VSCode has come a long way since then, but still no encoding support in the extension API? Perhaps a full-blown feature that allows the encoding to be modified is too far down the priority list. However, it seems like it shouldn't be too difficult to add a simple read-only Even if the value shown in the status bar is a guess as seems to be suggested in earlier comments, it would be better than nothing. As an extension writer, I'd rather use VSCode's best guess at the encoding than try to figure it out on my own. |
The most sane way to get features like this, or column select, is to use a different editor. IMHO |
ping for it |
I looked at the code and I thought the coding was tied to the document, but it's actually tied to the editor. I spent some time exposing it to the /**
* Represents an editor that is attached to a {@link TextDocument document}.
*/
export interface TextEditor {
...
getEncoding(): Promise<string | undefined>;
setEncoding(encoding: string, mode: "encode" | "decode"): Promise<void>;
} and then in the json extension using export async function activate(context: ExtensionContext) {
...
const editer = window.activeTextEditor;
if (editer) {
outputChannel.appendLine("ok");
outputChannel.appendLine((await editer.getEncoding()) ?? "null");
await editer.setEncoding("utf16be", "encode");
outputChannel.appendLine((await editer.getEncoding()) ?? "null");
}
} It worked! When opening the file he changed the document from utf8 to utf16be. |
I have moved it to toDispose.push(
workspace.onWillSaveTextDocument((e) => {
e.waitUntil(Promise.resolve([TextEdit.setEncoding("utf8")]));
})
);
// or
window.activeTextEditor.edit((textEdit) => {
textEdit.setEncoding("utf8");
}); But And I didn't follow the rules of eslint(local/code-import-patterns) and couldn't submit the code, so I had to return to the previous method. If I want to provide I've spent a lot of time on this and now I'm going back to work😥. https://github.com/Tarrowren/vscode/tree/textedit-encoding |
@takekazuomi do you create a MR for this? |
I was getting ready to file a bug against editorconfig for this. That the microsoft-affiliated editor does not let editorconfig safeguard the charset of windows-specific files that cannot be in utf8 in my project is too ironic and not funny in 2024. When merge? |
... yet we are still waiting? 🙃 |
确实,我也从20年等到今天 |
把这个问题在里程碑下面讨论一下 |
Currently there are only two fields in the TextEditorOptions API, a few other TextEditor-related APIs, and none of them is able to deal with the text buffer's encoding.
Comparing to Atom's TextEdit API, that is far from enough.
Most importantly, the API limitation makes it (seems) impossible for vscode-editorconfig to implement features like
charset
support, which is a crucial need for many people.The text was updated successfully, but these errors were encountered: