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

Expose (Re)open With Encoding as API #210041

Closed
giubacc opened this issue Apr 10, 2024 · 2 comments
Closed

Expose (Re)open With Encoding as API #210041

giubacc opened this issue Apr 10, 2024 · 2 comments
Assignees
Labels
*duplicate Issue identified as a duplicate of another issue(s) file-encoding File encoding type issues

Comments

@giubacc
Copy link

giubacc commented Apr 10, 2024

Hi,

In our company we are currently using Eclipse as official IDE.
We are in the process to also try other IDEs, and vscode is a desiderable one we would like to promote as official IDE.
Anyway, we are currently facing a problem trying to keep a strict consistency with the file encoding defined with the Eclipse's settings (this is our source of truth deciding what encoding applying to a document).
We thought that developing a vscode extension reading the Eclipse settings could suffice for this need, but we stumbled into a possible limitation vscode side.
We gave a look to the vscode APIs and we realized that it seems not to be available an API to select the encoding for the document being edited.

an approach (workaround like) could be to use this fragment when saving a document using an arbitrary encoding:

import * as vscode from 'vscode';

// Function to save a document with a specified encoding
async function saveWithEncoding(document: vscode.TextDocument, encoding: string): Promise<boolean> {
    try {
        await document.save({ encoding });
        return true;
    } catch (error) {
        console.error('Error saving document:', error);
        return false;
    }
}

// Example usage
const activeEditor = vscode.window.activeTextEditor;
if (activeEditor) {
    const document = activeEditor.document;
    saveWithEncoding(document, 'utf16le'); // Example encoding
}

But this is not sufficient, we would need an API acting as the built-in function: Reopen With Encoding.
Any advice on how to achieve this with the current API set would be great; if such API does not currently exist, we could be interested into helping creating new one.
This is the issue opened explaining the need we would like to implement in the extension.

@giubacc giubacc changed the title Expose (Re)open With Econding as API Expose (Re)open With Encoding as API Apr 10, 2024
@bpasero bpasero added the file-encoding File encoding type issues label Apr 15, 2024
@bpasero
Copy link
Member

bpasero commented Apr 15, 2024

/duplicate #824

@vscodenpa vscodenpa added the *duplicate Issue identified as a duplicate of another issue(s) label Apr 15, 2024
@vscodenpa
Copy link

Thanks for creating this issue! We figured it's covering the same as another one we already have. Thus, we closed this one as a duplicate. You can search for similar existing issues. See also our issue reporting guidelines.

Happy Coding!

@vscodenpa vscodenpa closed this as not planned Won't fix, can't repro, duplicate, stale Apr 15, 2024
@microsoft microsoft locked and limited conversation to collaborators Jun 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*duplicate Issue identified as a duplicate of another issue(s) file-encoding File encoding type issues
Projects
None yet
Development

No branches or pull requests

4 participants