-
Notifications
You must be signed in to change notification settings - Fork 18k
x/tools/gopls: bad state after creating new directory and package #37978
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
Thank you for the report and the log! A few quick thoughts / questions:
It seems you are using modules - are you opening VS Code at the root of your module or a subdirectory? It seems like we're treating your package as an ad-hoc package. Something we can definitely do is make sure that we don't try to reload packages with the path |
Yes.
I typed
Root, though it's a workspace with multiple folders. In case it's relevant, the two other folders are a Go project (with |
Hm, based on the log that doesn't seem to be the case. Would you mind sharing a log where you follow that same workflow just so that I can confirm if things are working properly?
Thanks for the confirmation. It sounds like |
I am actually able to reproduce the bug consistently, doing exactly what I described:
package client
type Client struct {
hc *http.Client
}
Here's a gopls log from doing the above, and nothing else: gopls.log.gz. |
Thanks for attaching the log! It's helped me notice a few deficiencies in the way we log for multi-project workspaces, so I will mail a change to address some of them soon. Another question about your workspace - it seems like only one Also, are you able to reproduce this if you only open that project instead of your multi-project workspace? |
Yes.
No. |
I am also able to reproduce the bug if I have only one project in the workspace. So it's not related to the other project in the workspace that also has a |
Change https://golang.org/cl/225117 mentions this issue: |
Change https://golang.org/cl/225137 mentions this issue: |
Thanks! I've mailed the above changes to address some of the immediate issues I noticed from the logs, so I will ask you to try again after those are merged. If you'd like to try one more thing in the meantime, could you create a repro log with a single-project workspace? It might make it a bit easier for me to parse your log. If not, totally fine to wait until after those changes are merged. Thanks for your help on this! |
I'm not sure if this is entirely the correct approach, but at the very least we should never pass "command-line-arguments" to packages.Load. We still need to cache packages with the path "command-line-arguments" to avoid an excessive number of calls to packages.Load. Updates golang/go#37978 Change-Id: I1b5263a3dab95aacd797f03f742069fd0c53619c Reviewed-on: https://go-review.googlesource.com/c/tools/+/225117 Run-TryBot: Rebecca Stambler <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]>
For debugging purposes, we print the output of `go env` on start. Now, we print a view-specific `go env`, which will helps us when debugging multi-project workspaces. Additional information included: the folder of the view, if the view has a valid build configuration, and the build flags for the view. Updates golang/go#37978 Change-Id: Iadffd46f8ac5410971558a304b8bbcb2f9bdbcc3 Reviewed-on: https://go-review.googlesource.com/c/tools/+/225137 Run-TryBot: Rebecca Stambler <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]>
These changes are now merged, and you can try them out by updating to |
Thanks! Unfortunately, no difference. Here's a log. I will get you a log from a single-project workspace. |
Uh, I don't know what happened. After reloading the VSCode window ( |
Reloaded the window, and am once again able to reproduce it, even in a workspace that contains just the one Go project: gopls.log.gz. I'm no longer not able to reproduce it. |
By the way, I'm installing from source: $ GO111MODULE=on go get golang.org/x/tools/gopls@master
go: downloading golang.org/x/tools/gopls v0.1.8-0.20200324201824-1fc30e1f4ccc
go: golang.org/x/tools/gopls master => v0.1.8-0.20200324201824-1fc30e1f4ccc
go: downloading golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d
# golang.org/x/tools/gopls/internal/hooks
.go/pkg/mod/golang.org/x/tools/[email protected]/internal/hooks/hooks.go:19:9: options.URLRegexp undefined (type *source.Options has no field or method URLRegexp) Latest commit: $ git log -1 --no-abbrev
commit 1fc30e1f4ccc2986b7ad007d40afcf96be78a429 (HEAD, origin/master, origin/HEAD)
Author: Rob Findley <[email protected]>
Date: Mon Mar 23 17:26:05 2020 -0400
internal/lsp/regtest: remove redundant T and ctx params from regtest funcs |
Thanks for the log! I am now able to reproduce this issue myself. I'll aim to have a fix soon. By the way, some of the error messages in your logs ( |
Super, thank you.
Good catch, I didn't realize that!
Oh, I didn't realize it took multiple arguments. For global installs, it maybe resolves them together as if they were in the same |
Change https://golang.org/cl/225317 mentions this issue: |
What did you do?
Created a file and typed a bunch of code. After saving, gopls correctly added an import to
net/http
.What did you expect to see?
No errors.
What did you see instead?
However, it still displays a marker for the error
undeclared name: http
, and on the wrong line.This kind of thing happens fairly commonly (and I just restart gopls), but in this case it was a brand new file, so the section of log starts at the initial opening of the file, so hopefully this has all relevant log messages to diagnose the problem.
Log
gopls.log.gz
Build info
Go info
The text was updated successfully, but these errors were encountered: