-
Notifications
You must be signed in to change notification settings - Fork 18k
x/tools/gopls: formatting result breaks the code #45648
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
Comments
Thanks for the report. This looks very broken. I am not able to reproduce. This is not surprising: if formatting were so easily broken, there would be many more reports. I suspect, instead, that there is either a conflicting formatting tool running in your editor, or perhaps some very strange edge case bug in the formatting logic, perhaps related to line endings. If you are able to reproduce, we can try to narrow this down together. Questions for you:
|
@findleyr I am on windows and made the test file with windows line endings and I am not able to reproduce this on gopls
|
@AlexRouSg thanks for trying. I actually just noticed that GOOS/GOARCH is |
Yes, not only in VSCode but also
I had disabled all other extensions and only kept the "Go" extension, and made VSCode
I did it on my local MacOS and the Linux remote development.
if someone copy the original code to vim, please use type Issue struct{ // no space between "struct" and "{" fai /tmp $ echo -n 'cGFja2FnZSBtYWluCgp0eXBlIElzc3VlIHN0cnVjdHsKCUR1bW15IGludAp9Cgp2YXIgKAoJZm9vID0gImJhciIKCXNvbWVJc3N1ZXMgPSBbXWludGVyZmFjZXt9ewoJCQlJc3N1ZXt9LAoJCQlJc3N1ZXt9LAoJCQlJc3N1ZXt9LAoJfQop' |base64 -d > issue.go
fai /tmp $ gopls format issue.go
2021/04/21 00:17:43 Error:2021/04/21 00:17:43 go/packages.Load: err: exit status 1: stderr: go: cannot find main module; see 'go help modules'
snapshot=0
directory=/tmp
query=[./ builtin]
packages=0
2021/04/21 00:17:43 Error:2021/04/21 00:17:43 initial workspace load failed: err: exit status 1: stderr: go: cannot find main module; see 'go help modules'
: packages.Load error
package main
type Issue struct{
{
{
Dummy int
{
}
{
{
var (
{
foo = "bar"
{
someIssues = []interface{}{
{
Issue{},
{
Issue{},
{
Issue{},
{
}
Dummy int |
This comment has been minimized.
This comment has been minimized.
Thanks so much for the careful repro steps! This is very helpful. Surprisingly, I still cannot repro. We're brainstorming how this could be possible. > echo -n 'cGFja2FnZSBtYWluCgp0eXBlIElzc3VlIHN0cnVjdHsKCUR1bW15IGludAp9Cgp2YXIgKAoJZm9vID0gImJhciIKCXNvbWVJc3N1ZXMgPSBbXWludGVyZmFjZXt9e
woJCQlJc3N1ZXt9LAoJCQlJc3N1ZXt9LAoJCQlJc3N1ZXt9LAoJfQop' | base64 -d > issue.go
> gopls format issue.go
package main
type Issue struct {
Dummy int
}
var (
foo = "bar"
someIssues = []interface{}{
Issue{},
Issue{},
Issue{},
}
)
> gopls version
golang.org/x/tools/gopls v0.6.10
golang.org/x/tools/gopls@(devel)
> go version
go version go1.15.6 linux/amd64 |
Yes, me too. Both on MacOS and Linux, |
Can someone who can reproduce this show us the output of |
|
OK. We're quite stumped, so, silly as it seems, can you attach your gopls binary to this issue? |
Thanks, that was extremely helpful. The problem is that the latest version of Reinstall without the |
@heschi Thanks for your detailed analysis. |
@zaakn can you tell us how you installed |
What version of Go are you using (
go version
)?VSCode
settings.json
All of the go/gopls related parameters use default values, but
"go.languageServerFlags": ["-rpc.trace"]
for the tracing.What did you do?
The formatting result on saving broke the code.
IMPORTANCE to reproduce:
The comments just for explanation, please remote them before testing.
What did you expect to see?
What did you see instead?
gopls (server) trace output
gopls_v0.6.10.darwin.tar.gz
gopls_v0.6.10.linux_x86_64.tar.gz
The text was updated successfully, but these errors were encountered: