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

0.6.71 rejects all changes, until goreturns is updated #1447

Closed
trytriangles opened this issue Jan 8, 2018 · 18 comments
Closed

0.6.71 rejects all changes, until goreturns is updated #1447

trytriangles opened this issue Jan 8, 2018 · 18 comments

Comments

@trytriangles
Copy link

The update to 0.6.71 has introduced a strange bug for me, which persists even despite uninstalling and re-installing the plugin: the formatting process rejects any and all changes, with the sole exception of defining the package name.

vscode-go_problem_a

Any lines I add to a file will be erased the moment I save. Any lines I delete from a file will be restored the moment I hit save. It doesn't remove legitimate lines that were already there – if I write some code in vim, then open the file in VS Code and edit it, saving only removes the lines VS Code added. (It does still remove illegitimate lines, like an unused import.)

vscode-go_problem_b

I don't have auto-save on, and I haven't customised any of VSCode-Go's settings.

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Jan 8, 2018

Do you see any errors in the console? Help -> Toggle Developer Tools -> Console
Until the issue is resolved, you can add the below in your settings

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

@ramya-rao-a
Copy link
Contributor

Does manual formatting remove the changes as well?

@ramya-rao-a
Copy link
Contributor

Can you repro it if you added the setting "go.formatTool": "goimports" or "go.formatTool": "gofmt"?

@harunrzl
Copy link

harunrzl commented Jan 9, 2018

I've got similar error. Somehow it solved after I install this package:
go get -u -v sourcegraph.com/sqs/goreturns

@ramya-rao-a
Copy link
Contributor

Thanks @harunrzl. goreturns is the default tool used for formatting.

@ryantriangles Does that help you as well?

@Deleplace
Copy link

Deleplace commented Jan 9, 2018

Same problem (on Linux).
A top-popin said "Works better with latest version of goreturns, install it?", I clicked OK and now it is fixed.
If you don't get the popin, try the go get command given by @harunrzl

@trytriangles
Copy link
Author

Setting "go.formatTool" to "goimports" or "gofmt" eliminates the problem, so it does seem to be something with goreturns.

Invoking goreturns manually works fine, and doesn't remove the lines that it removes in vscode-go.

Despite installing goreturns manually (with go get -u -v sourcegraph.com/sqs/goreturns), the first launch of VS Code in a Go folder always triggers the prompt "The Go extension is better with the latest version of 'goreturns', Update/Cancel." Clicking Update successfully triggers another install of goreturns, but doesn't solve the problem (neither within the session nor after re-launching).

@ramya-rao-a
Copy link
Contributor

@ryantriangles Looks like the goreturns that is getting updated and the one that is getting used by the Go extension are different in your case. Can you search your machine for the file goreturns (goreturns.exe in case of Windows) and see if you have more than 1?

I am able to repro the issue by installing an older version of goreturns. The newer version supports the flag srcdir which the latest version of the Go extension needs. If user still has the older version, the Go extension re-tries formatting by calling goreturns again, but this time without the srcdir flag. Looks like there was a race condition causing the current issue in this case.

I have pushed a fix which you can try as well.

@ramya-rao-a ramya-rao-a changed the title 0.6.71 rejects all changes, making .go files read-only 0.6.71 rejects all changes, until goreturns is updated Jan 9, 2018
@ramya-rao-a
Copy link
Contributor

I've published a release that should fix this issue.

Sorry for the trouble everyone.

@zengming00
Copy link

Now, code formatting never work☹

@wangjieyanda
Copy link

me too,the vscode formatting never work,I cannnot write code with the ide

@ramya-rao-a
Copy link
Contributor

@zengming00 @wangjieyanda Which platform are you on? Windows? Mac? Linux?

@wangjieyanda
Copy link

it was solved in 0.6.72 version,thanks @ramya-rao-a

@WenhaiLin
Copy link

@ramya-rao-a The binary program of goreturns is not updated automatically when go-extension has been updated on Mac.

@zengming00 @wangjieyanda You can build the binary program of goreturns manually and then replaces it with the new on.

@ramya-rao-a
Copy link
Contributor

@WenhaiLin Do you get the pop up asking you to update goreturns?

@WenhaiLin
Copy link

WenhaiLin commented Jan 15, 2018

@ramya-rao-a Yes, it happen time and time again. So I build the binary program of goreturns manually.

@ramya-rao-a
Copy link
Contributor

@WenhaiLin Then go get -u must be failing to update the tool. I found myself in a weird setup where go get -u would update the source code of the Go tool I am updating but would not update the binary.

Try running it manually
go get -u -v sourcegraph.com/sqs/goreturns. If you have set go.toolsGopath then set export GOPATH=<value of the the go.toolsGopath> before running go get and then set it back to the older GOPATH

@byrain
Copy link

byrain commented Jan 18, 2018

@ramya-rao-a @WenhaiLin
thank you so much! Build goreturns manually solved my problem.
OS: MAC. Vscode version:1.19.2

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

No branches or pull requests

8 participants