LaurentTreguier / vscode-uncrustify

Code format using uncrustify
66 stars 10 forks source link

Add 'useReplaceOption' for the document saved as UTF8 with BOM. #36

Closed kishi-yama closed 6 years ago

kishi-yama commented 6 years ago

Hi, I'm a Japanese developer.

I added useReplaceOption because I found out that this extension cause writing BOM twice to the document saved as UTF8 with BOM and I understood this problem is able to avoid if use --replace option.

VSCode will save the document as UTF8 with BOM if Japanese comments are contained in it.

I suppose this problem is derived from not supporting utf8bom encoding in Node.js or vscode.TextDocument.getText function.

Thanks.

LaurentTreguier commented 6 years ago

I can't reproduce this, for me an UTF-8 encoded file still has only one BOM even after formatting multiple times. This may be a bug in uncrustify. What is the version of uncrustify you are using, and which language are you trying to format ? I have no problem with version 0.67 (the latest version as of now).

kishi-yama commented 6 years ago

Thank you for your reply.

I also used uncrustify ver. 0.67, and tried to format the C# source code with Japanese comments.

I've tried to build uncrustify from source code for debugging, and realized that the file is saved as UTF8 with BOM when Japanese comments are contained in the C# source code, on the other hand, it is saved as UTF8 (not with BOM) when only ascii comments are contained.

I took screenshots when the problem occurred.

2018-07-31 2 24 48

2018-07-31 2 16 54

FYI, this problem is not reproduced if use uncrustify in command line directly.

LaurentTreguier commented 6 years ago

I still couldn't reproduce this for some reason. I merged this anyway, with some modification: when uncrustify.useReplaceOption is used, the document is saved before begin formatted. Otherwise, if a document is not saved on the disk, changes in VSCode will not be taken into account when formatting.

kishi-yama commented 6 years ago

I updated your extension via VSCode and the issue was fixed, thanks.