Go: x/tools/gopls: provide a way to suppress ā€œfailed to compileā€ notifications

Created on 16 Aug 2020  Ā·  16Comments  Ā·  Source: golang/go

This warning pops up constantly for me, often several times a minute. There is no way I see to dismiss it permanently. I don't know what's wrong, and usually I don't care; I'm in the midst of typing or doing other work and it is a distraction. It always seems to recover by itself.

I'd love some way to suppress the notification, maybe a setting or a button in the notification itself. If set, maybe the "failed to compile" message, with useful detail, could go to the console instead, which is where I go looking if things aren't working as expected.

Tools gopls

Most helpful comment

OK, yes, this seems to be a GOPATH-specific bug in some mix of the go command and go/packages.

@stamblerre seems to enjoy enabling this popup and then fixing go/packages edge cases, so perhaps she'll have something to say here.

All 16 comments

This error only pops up if gopls is in a bad enough state that we haven't been able to load any information for the packages in your workspace. It's almost meant to be annoying because we want the user to pay attention to it, but we are considering changing the frequency with which it pops up (https://golang.org/cl/248623).

Do you mind sharing your logs when you see this error? I really would not expect it to appear frequently if things are working correctly.

I just started a different project, so this might not have the same root cause as before, but I'll just dump all instances here as they occur.

The code in the workspace failed to compile (see the error message below). If you believe this is a mistake, please file an issue: https://github.com/golang/go/issues/new. github.com/josharian/native [github.com/josharian/native.test] has no metadata

No output at all for gopls. gopls server has a bunch of entries like this:

[Trace - 10:06:44.652 AM] Sending request 'textDocument/codeLens - (409)'.
Params: {"textDocument":{"uri":"file:///Users/josh/src/github.com/josharian/native/endian.go"}}


[Trace - 10:06:44.652 AM] Received response 'textDocument/codeLens - (409)' in 0ms.
Result: null


[Trace - 10:06:44.653 AM] Sending request 'textDocument/codeAction - (410)'.
Params: {"textDocument":{"uri":"file:///Users/josh/src/github.com/josharian/native/endian.go"},"range":{"start":{"line":4,"character":19},"end":{"line":4,"character":19}},"context":{"diagnostics":[]}}


[Trace - 10:06:44.653 AM] Received response 'textDocument/codeAction - (410)' in 0ms.
Result: null

Under problems, I see:

{
    "resource": "/Users/josh/src/github.com/josharian/native/endian_test.go",
    "owner": "_generated_diagnostic_collection_name_#0",
    "severity": 8,
    "message": "package native_test; expected native",
    "source": "compiler",
    "startLineNumber": 1,
    "startColumn": 1,
    "endLineNumber": 1,
    "endColumn": 8
}

and

{
    "resource": "/Users/josh/src/github.com/josharian/native/endian_generic.go",
    "owner": "_generated_diagnostic_collection_name_#0",
    "severity": 8,
    "message": "undeclared name: binary",
    "source": "compiler",
    "startLineNumber": 3,
    "startColumn": 14,
    "endLineNumber": 3,
    "endColumn": 30
}

The first "problem" is bogus--native_test is a legitimate package name for an external test in a package called native.

The second "problem" is bogus--it is complaining about a line that reads import "encoding/binary".

@josharian We need the full log, I'm afraid.

This might be a dupe of #40578 if you have a folder with no Go code in it and GO111MODULE=on.

Where should I look for the full log?

GO111MODULE is unset; there is Go code present.

I created a new directory, then ran

$ touch x.go
$ touch x_test.go
$ code .

I opened x.go and typed package p and hit save. I opened x_test.go and typed package p_test and hit save. Even before I managed to hit save on x_test.go, the compilation failed message started popping up.

Logs:

https://gist.github.com/josharian/e997023e436db031dba79a90249a9c9f

I can't reproduce. Before I dig any further, it might be worth trying 1.15, which fixed a number of bugs related to partial/missing package declarations. Can you update and make sure it's first on your PATH when you start VS Code?

Still reproduces with 1.15, exactly the same set of steps.

https://gist.github.com/josharian/6021b95602f3ae70820bf20ec80147ee

I noticed that this reproducer happened to be located as a GOPATH subdir. Sorry for not mentioning that earlier. I have also hit the same set of symptoms outside of GOPATH, so it didn't occur to me as relevant, but maybe there are multiple different things happening.

I am able to reproduce this consistently in vscode.

  1. Create a new workspace,
  2. add the go project (Add folder to workspace)
  3. add another non go project (Add folder to workspace)
  4. Go to go project and try to edit and save
  5. You will see the warning.

when it's only go project in the workspace, there will not be any warning when editing go files.
once another project is added, the warning will show up in the go project.

@zhaohanweng That is #40578. Please see https://github.com/golang/go/issues/40578#issuecomment-676623170.

OK, yes, this seems to be a GOPATH-specific bug in some mix of the go command and go/packages.

@stamblerre seems to enjoy enabling this popup and then fixing go/packages edge cases, so perhaps she'll have something to say here.

Change https://golang.org/cl/249703 mentions this issue: internal/lsp/regtest: reproduce empty xtest bug

Thanks for investigating this, @heschik. This is similar to a number of bugs we've seen with empty files--all related to https://github.com/golang/go/issues/39986. The go/packages fix here is likely not feasible, so I think the full resolution to this issue will have to come with https://github.com/golang/go/issues/39986, which will hopefully be released as part of Go 1.16. In the meantime, I will mail a CL to disable the pop-up.

Change https://golang.org/cl/250949 mentions this issue: internal/lsp, go/packages: work-around invalid files in GOPATH mode

@stamblerre I am now getting these pop-ups in another project. I just re-installed gopls at HEAD, or at least, I tried to. Should I...open a new issue? Do something else?

I just re-installed gopls at HEAD, or at least, I tried to.

What's the output of gopls version? To install at HEAD, run GO111MODULE=on go get golang.org/x/tools/gopls@master golang.org/x/tools@master. If that doesn't fix the issue, feel free to open a new issue and please attach the contents of the error message and your logs.

Was this page helpful?
0 / 5 - 0 ratings