-
Notifications
You must be signed in to change notification settings - Fork 32.8k
Provide encoding-related APIs for editor extensions #824
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
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.
👋 I need more input to know what extensions actually need here. My work covers 3 areas that we have in core today but it is well possible that I miss an important aspect that would not be covered by these 3 areas and/or one of the areas is not useful at all: Add a
|
Thanks for taking this one on @bpasero, for my extension, I think the APIs you are proposing would fit all the needs. Maybe there is some case for adding encoding parameters in FileSystemProvider interfaces so the provider could enforce some encoding for the underlying resource as need be. That said, someone could still get the encoding from the text document because they have the URI, probably more of a "nice to have". One other potential use case outside of the extension API could be a CLI option to set encoding for opening a file or diffing/merging files. Although you could mitigate this with user/extension encoding config defaults (until someone overrides them...). |
Fyi we are now also pushing proposed API in #241160 to |
All, here is an updated proposal for API related to encoding/decoding: export interface TextDocument {
/**
* The file encoding of this document that will be used when the document is saved.
*
* Use the {@link workspace.onDidChangeTextDocument onDidChangeTextDocument}-event to
* get notified when the document encoding changes.
*/
readonly encoding: string;
}
export namespace workspace {
/**
* Opens a text document with the provided encoding.
*/
export function openTextDocument(uri: Uri, options?: { encoding?: string; }): Thenable<TextDocument>;
export function openTextDocument(path: string, options?: { encoding?: string; }): Thenable<TextDocument>;
export function openTextDocument(options?: { encoding?: string; }): Thenable<TextDocument>;
/**
* Decodes the content from a `Uint8Array` to a `string`.
*
* If no encoding is provided, will try to pick an encoding based
* on user settings and the content of the buffer (for example
* byte order marks).
*/
export function decode(content: Uint8Array, uri: Uri | undefined, options?: { encoding: string }): Thenable<string>;
/**
* Encodes the content of a `string` to a `Uint8Array`.
*
* If no encoding is provided, will try to pick an encoding based
* on user settings.
*/
export function encode(content: string, uri: Uri | undefined, options?: { encoding: string }): Thenable<Uint8Array>; I think that As for
Finally, I am not seeing a good use case for the initially suggested |
@bpasero hello! So it would be possible to use |
@SunsetTechuila Thing is, if the document is dirty (has changes by the user), we cannot force this to happen. We can also not really just save the document because it may result in broken contents, given the encoding maybe wrong. So we throw an error. If you call Thinking about this more, I wonder if we need a way to change the encoding of the document without forcing it to save. We do not really offer this to the user today, we only have these 2 options: ![]() Or alternatively, as initially suggested, we go back to having the Can you clarify the use case here? |
With the new proposed APIs already pushed, one could emulate the
|
Continues in #241449 for finalisation. I encourage extension authors to play with the proposed API and report issues as they encounter them. Thanks 🙏 Fyi, extension tests are here showing how to use the new API:
|
Fyi we plan to finalise the API for our April release: #246016 |
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: