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

add support for charset #35

Open
SamVerschueren opened this issue Mar 23, 2016 · 24 comments
Open

add support for charset #35

SamVerschueren opened this issue Mar 23, 2016 · 24 comments

Comments

@SamVerschueren
Copy link
Collaborator

They're working on it to bring that functionality via an API so we can use that. But it's not possible at the moment though.

@jednano jednano added this to the EditorConfig 1.0 milestone Mar 24, 2016
@jednano
Copy link
Member

jednano commented Apr 14, 2016

I believe this is now possible with the files.encoding setting?

@SamVerschueren
Copy link
Collaborator Author

If I'm not mistaken, we can't override the workspace settings of the user so this should be implemented in the API.

@jednano
Copy link
Member

jednano commented Apr 14, 2016

Ahh, you are correct.

@SamVerschueren
Copy link
Collaborator Author

Pinged them again to get the status on this API :)

@jednano
Copy link
Member

jednano commented Apr 14, 2016

@SamVerschueren can you reference (link to) the vscode issue here?

@be5invis
Copy link

any progress?

@jednano
Copy link
Member

jednano commented Jul 20, 2016

Nope.

@bizoo
Copy link

bizoo commented May 5, 2017

Still much needed for VSCode!
I don't think there's another way to correctly managed encoding without it.
So please look at it.

@brainz80
Copy link

brainz80 commented May 8, 2018

Looking at vscodes source-code I found this (there's a feature to reopen a file with a different encoding):

vscode\src\vs\workbench\browser\parts\editor\editorStatus.ts:

return this.quickOpenService.pick(picks, {
	placeHolder: isReopenWithEncoding ? nls.localize('pickEncodingForReopen', "Select File Encoding to Reopen File") : nls.localize('pickEncodingForSave', "Select File Encoding to Save with"),
	autoFocus: { autoFocusIndex: typeof directMatchIndex === 'number' ? directMatchIndex : typeof aliasMatchIndex === 'number' ? aliasMatchIndex : void 0 }
}).then(encoding => {
	if (encoding) {
		activeEditor = this.editorService.getActiveEditor();
		encodingSupport = toEditorWithEncodingSupport(activeEditor.input);
		if (encodingSupport && encodingSupport.getEncoding() !== encoding.id) {
			encodingSupport.setEncoding(encoding.id, isReopenWithEncoding ? EncodingMode.Decode : EncodingMode.Encode); // Set new encoding
		}
	}
});

toEditorWithEncodingSupport looks like this:

function toEditorWithEncodingSupport(input: IEditorInput): IEncodingSupport {

	// Untitled Editor
	if (input instanceof UntitledEditorInput) {
		return input;
	}

	// Side by Side (diff) Editor
	if (input instanceof SideBySideEditorInput) {
		const masterEncodingSupport = toEditorWithEncodingSupport(input.master);
		const detailsEncodingSupport = toEditorWithEncodingSupport(input.details);

		if (masterEncodingSupport && detailsEncodingSupport) {
			return new SideBySideEditorEncodingSupport(masterEncodingSupport, detailsEncodingSupport);
		}

		return masterEncodingSupport;
	}

	// File or Resource Editor
	let encodingSupport = input as IFileEditorInput;
	if (types.areFunctions(encodingSupport.setEncoding, encodingSupport.getEncoding)) {
		return encodingSupport;
	}

	// Unsupported for any other editor
	return null;
}

Maybe this can be to some help. Could it be the necessary feature is there after all??

@brainz80
Copy link

Throwing some more virtual balls:

Looking at vscode.d.ts I found this function:

/**
 * Get a workspace configuration object.
 *
 * When a section-identifier is provided only that part of the configuration
 * is returned. Dots in the section-identifier are interpreted as child-access,
 * like `{ myExt: { setting: { doIt: true }}}` and `getConfiguration('myExt.setting').get('doIt') === true`.
 *
 * When a resource is provided, configuration scoped to that resource is returned.
 *
 * @param section A dot-separated identifier.
 * @param resource A resource for which the configuration is asked for
 * @return The full configuration or a subset.
 */
export function getConfiguration(section?: string, resource?: Uri | null): WorkspaceConfiguration;

permalink to source

Example of usage:

const config = workspace.getConfiguration('launch', vscode.window.activeTextEditor.document.uri);

Could this be to any help?

@jednano
Copy link
Member

jednano commented Aug 30, 2018

@brainz80 your 2nd comment doesn't seem to have anything to do with encoding. The 1st one does, but those look like private methods, no?

@brainz80
Copy link

@jedmao I guess your right. Looked a bit closer into the getConfiguration() -function and it seems the only data that can be queried though it has to do with launch and tasks settings:

Note: Workspace and Workspace Folder configurations contains launch and tasks settings. Their basename will be part of the section identifier. The following snippets shows how to retrieve all configurations from launch.json

https://code.visualstudio.com/docs/extensionAPI/vscode-api#WorkspaceConfiguration

As with the 1st comment they seem to be private methods; but maybe the logic in them could be to use?

I've tried to contact a couple of guys over at Microsoft with hopes of getting them to work on adding encoding support to the API. Unfortunately it seems they're more interested in working with their own bugs / feature-updates than taking on "user-reported" ones ... or so it seems at least.

@jednano
Copy link
Member

jednano commented Sep 1, 2018

I'd rather wait until they have a supported API for this feature.

@KUGA2
Copy link

KUGA2 commented May 21, 2019

Any news on this?

@brainz80
Copy link

brainz80 commented May 21, 2019 via email

@KUGA2
Copy link

KUGA2 commented May 21, 2019

Is there a issue or request on vscode we could vote on?

@jednano
Copy link
Member

jednano commented May 21, 2019

@KUGA2 GitHub already shows it linked above. microsoft/vscode#824

@Masterxilo
Copy link

This is an absolute must. I am working with some legacy stuff here that has no idea about utf-8

@lgaitan
Copy link

lgaitan commented Oct 13, 2020

Any update on this?
Maybe some help needed?

@jednano
Copy link
Member

jednano commented Oct 13, 2020

There's nothing that can be done until Microsoft (or someone) fixes microsoft/vscode#824.

@snebjorn
Copy link

Perhaps OP can be edited to encourage people (+friends & family) to go and upvote microsoft/vscode#824

@lygstate
Copy link

lygstate commented Dec 5, 2023

monitor this

@leaumar
Copy link

leaumar commented Oct 22, 2024

Christ, I thought I was going nuts and couldn't write a working glob anymore until I got the desperate idea to check out the extension details. It's 2024 and vscode ironically does not let you safeguard the encoding of files that windows wants in not-utf8. You can't make this up.

@DecimalTurn
Copy link

DecimalTurn commented Oct 23, 2024

While it would be nice to have charset support directly in VS Code, you can always use the working-tree-encoding attribute in a .gitattributes file as a workaround in the meantime. For example, if you have to support PowerShell (v5 or lower1), you can use:

*.ps1 text working-tree-encoding=UTF-16

This will make sure that an error message will be displayed if a UTF-8 (no BOM) encoding is used for a newly created file:
fatal: BOM is required in 'test.ps1' if encoded as UTF-16

Footnotes

  1. PowerShell v6 and higher supports UTF-8 (no BOM) by default (source).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests