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

Encoding During Format On Save #545

Closed
dacarmr opened this issue Jan 14, 2022 · 8 comments · Fixed by #550
Closed

Encoding During Format On Save #545

dacarmr opened this issue Jan 14, 2022 · 8 comments · Fixed by #550
Labels
priority:high type:bug Something isn't working
Milestone

Comments

@dacarmr
Copy link

dacarmr commented Jan 14, 2022

Firstly, thank you so much for this project.

I am part of an international team and when formatting utf8 files with unicode chars the chars get replaced with "?".
In our .editorconfig we have charset=utf-8
Then in our cs file we have this line:

private const char test = '。';

After saving the file it becomes:

private const char test = '?';

For now I can use '\u' but sometimes we have Japanese text in files so we do not want those to break.

Sorry I left out a lot of needed info...

Using VS2022, global install + extension.
Using command "dotnet csharpier ." doesn't cause this issue.
"Reformat with CSHarpier on Save" = true causes the issue on save.

Thanks.

@belav
Copy link
Owner

belav commented Jan 14, 2022

Is there a public repo that I could use to recreate the issue? The unicode character formats as expected when using csharpier.com and I won't have access to a computer to test it properly until next week. In theory csharpier is supposed to leave files in the same encoding that it finds them.

Also if you end up trying it yourself on csharpier.... It seems like the cert has just expired.

@belav belav added priority:high type:bug Something isn't working labels Jan 14, 2022
@dacarmr
Copy link
Author

dacarmr commented Jan 14, 2022

I'll try create a public repo over the weekend. On csharpier it works correctly.

@dacarmr
Copy link
Author

dacarmr commented Jan 14, 2022

I've uploaded a sample Here
I've updated the original comment, this appears to be the vs2022 extension issue with format on save.

I'm assuming this is where the trouble happens:

https://github.com/belav/csharpier/blob/master/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/CSharpierProcessSingleFile.cs#L39

Probably need to set the encoding correctly. I'm not sure what "correctly" means though :D.

@belav
Copy link
Owner

belav commented Jan 14, 2022

I think I should be able to reproduce it now and get a fix out pretty quickly next week. My guess is that properly means determining the encoding of the file earlier, and then reading the output using that encoding.

@belav
Copy link
Owner

belav commented Jan 19, 2022

The fix for this is mostly ready to go, I just need to do some more testing. It will require a new version of csharpier. And a new version of the VS and rider extensions.

@belav belav added this to the 0.14.0 milestone Jan 20, 2022
belav added a commit that referenced this issue Jan 22, 2022
* Adding documentation for husky.net + implement it. Clean up the solution a bit with notarget projects.

* self code review

* More self code review

* rename file

* Make sure the pre-commit hook is opt in

* Update task-runner.json

* Narrowing down where the unicode encoding issue is for #545

* Adding some notes and logging.

* Getting UTF8 working on vs and vscode

* Cleanup plus getting rider working with utf8

* some cleanup

* Self code review

* Update CliTests.cs
@belav
Copy link
Owner

belav commented Jan 22, 2022

This is resolved with csharpier 0.14.0 + 1.0.1 of the VS extension or 1.0.4 or the rider extension. The rider extension requires jetbrains to manually approve each update so it may not be out for a couple of days.

@dacarmr
Copy link
Author

dacarmr commented Jan 25, 2022

Thank you so much.

@belav
Copy link
Owner

belav commented Jan 26, 2022

You are welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority:high type:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants