-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
x/tools/gopls: improve error message when using wrong go command with Go source distribution #35520
Comments
Thank you for filing a gopls issue! Please take a look at the Troubleshooting guide, and make sure that you have provided all of the relevant information here. |
I (partially) figured out what's going on here: the golang repo is special in that it can only be properly compiled or analyzed when GOROOT is set to its own location. This is because much of its own code is importable as "standard packages" via GOROOT, and GOROOT packages take precedence. So if GOROOT points to a different installation of go, those packages will get imported instead, resulting in access errors for packages under So, the fix is to set GOROOT when working with the golang repo. I think this issue should remain open to fix the meta issue here, which is that |
Note that generally you should not set the |
@ianlancetaylor thanks for jumping in. Can you clarify a bit? I just described a circumstance where setting |
As far as I can see, it shouldn't be needed even in this case. I don't understand why it is needed. Is |
Ah, interesting, let's see if we can get to the bottom of it.
Nope
/usr/local/Cellar/go/1.13.4/libexec
To be clear, it's not that I want to use a different GOROOT, just that things break if I don't. The value I need to change it to is the location of the local clone of https://github.com/golang/go/ that I'm trying to analyze with gopls.
Just |
Change your |
Ah that makes sense, thanks. (For posterity: gopls figures out the root by shelling out to With that resolved, any thoughts on ways we could make this easier for newcomers to the golang/go repo? If they're like me, they'll find a few things very broken without obvious reasons or solutions:
These are all simple once you know that, when using any kind of tooling on the contents of the golang repo, you must use the go binary built from that same repo (or set GOROOT to that repo). But AFAICT, this isn't mentioned anywhere -- should we add it somewhere, maybe https://golang.org/doc/contribute.html? Even better would be if things could be changed so that wasn't a requirement -- in a perfect world, I'd be able to analyze the code in the golang repo without having to build that repo or mess with my path. But I assume that would be a huge/difficult change at this point. |
@russelldavis: I think you may have been looking at a file that is specifically broken with |
@stamblerre sadly it's not just that file. It seems to be broken for everything under https://github.com/golang/go/tree/master/src/cmd. As I mentioned above, tooling in IDEs like VSCode and GoLand is broken for all of those files as well, for the same reason. |
GoLand doesn't use |
The larger issue I'm talking about here isn't specific to The point is that an import of, e.g., This is definitely why there are issues in GoLand, and I'm pretty sure the cause of the issues in VSCode and gopls. With that in mind, hopefully my suggestions at #35520 (comment) make more sense? Here's a trace of |
I think probably that the best option here is for us to make error messages more explicit in One option that is currently available to you (to avoid mucking with your
I don't think it's possible to achieve this through the |
check
on golang repo files times out
This just bit me too. There is a somewhat cryptic reference to GOROOT in the logs, but the message doesn't say what the user should do. If the user isn't looking at the log right then, the relevant message is hard to find in among all the other log messages. Perhaps opening a source distribution with mismatched GOROOT deserves a special check and a visible message. |
The last thing remaining to improve here are the error messages when someone is using the wrong |
What did you do?
From the go/src/cmd dir:
What did you expect to see?
The command succeeds.
What did you see instead?
The command times out after 30s. Output: gopls.txt
Build info
Go info
The text was updated successfully, but these errors were encountered: