Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

When I save file Chinese will be converted into ��� ,Does anyone know why? #1469

Closed
chenenze opened this issue Jan 17, 2018 · 13 comments

Comments

@chenenze
Copy link

image

The problem disappeared when I uninstall this plugin

@ramya-rao-a
Copy link
Contributor

On save, the only extra edits being performed are the formatting edits. Install the extension and try the below

  • Add "go.formatTool": "gofmt" to your settings and reload VS Code. Do you still see the issue?
  • If you still see the issue, then add the below to your settings and try again
"[go]": {
    "editor.formatOnSave": false
   }

@chenenze
Copy link
Author

Thank you for your help! It's working

@chenenze
Copy link
Author

This problem reappeared when I was working for some time
This is my setting:
{
"team.showWelcomeMessage": false,
"go.formatTool": "gofmt",
"go.formatOnSave": false,
"files.autoSave": "afterDelay",
"files.autoSaveDelay": 2000,
"workbench.iconTheme": "vscode-icons",
}

@chenenze chenenze reopened this Jan 17, 2018
@ramya-rao-a
Copy link
Contributor

Can you get a consistent repro of the issue or does it happen randomly? If you can repro it consistently, then can you share a small sample code where you see the issue?

@chenenze
Copy link
Author

chenenze commented Jan 18, 2018

It's not randomly, When I click command+s save the file, This situation is repeated.

// 仅�������������������������用户点击【通过】时才确认

when I delete all the functions except this function,this problem has disappeared.

I try to write a testcase like this:

package main

func test() {
    // 仅在用户点击【通过】时才确认
}

But did not reproduce。

@ramya-rao-a
Copy link
Contributor

@chenenze I cannot help if I don't have a file that I can use to see the issue :(

@xfstart07
Copy link

xfstart07 commented Jan 20, 2018

I have the same issue。
image

@ramya-rao-a
Copy link
Contributor

@xfstart07 Please share a sample code where you can reproduce the issue consistently

@molon
Copy link

molon commented Jan 21, 2018

@ramya-rao-a I have share a private code to you on gitter~ :)

@ramya-rao-a
Copy link
Contributor

Thanks @molon, I can repro the issue, but am not sure what the root cause is.

Until I get around to fixing this, the workaround is to either disable the formatOnSave feature by adding the below to your settings

"[go]": {
 "editor.formatOnSave": false
}

OR you can downgrade to 0.6.69 version of the Go extension by

@ramya-rao-a
Copy link
Contributor

Alright, I found the problem!

Recently, I moved from using the execFile to spawn when creating the child process that runs the formatting tool.

When using execFile there is default utf-8 encoding that happens. When using spawn, the streams aren't encoded by default and we need to set the right encoding to ensure that the multi-byte content in stdout gets handled properly.

I'll release an update with the fix in the next week or two. Until then, you can get the fix by doing the below:

@beta
Copy link

beta commented Jan 31, 2018

Thank you Ramya for your work! Another workaround before the issue is fixed is to run the formatter automatically with extensions that allow you to run commands on file save. These extensions include Run on Save and Trigger Task on Save. I am using Run on Save with the following configuration.

"emeraldwalk.runonsave": {
    "commands": [{
        "match": "\\.go$",
        "cmd": "goreturns -w ${file}"
    }]
}

Of course you should disable the built-in auto formatter with

"[go]": {
    "editor.formatOnSave": false
}

The -w argument makes goreturns format the code in place. That means, VS Code will reload the file due to external changes, instead of making minimal modifications which allow you to undo easily.

@ramya-rao-a
Copy link
Contributor

Just released an update (0.6.74) that has the fix for this issue. Thanks for your patience everyone!

@vscodebot vscodebot bot locked and limited conversation to collaborators Mar 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants