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: support ad-hoc packages with multiple files #36416
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. |
@Wingboy-Jim2: It sounds like you are working outside of GOPATH and without modules. |
What was a pain was that I have been working in such an ad hoc means for over two and a half years without any consequences. I have not seen any reason not to initialize a module, but it would have saved me a few hours of research and aggravation if the change in requirements had been more clearly presented. At the very least I hope that this ticket will reduce the time for anyone else functioning in such a fashion. |
The recommendation to use GOPATH is pretty common in Go documentation (for example, https://golang.org/doc/install#testing), and this specific issue with |
Change https://golang.org/cl/213458 mentions this issue: |
This change surfaces a warning to the user if they might be coding in a multi-file ad-hoc package. Updates golang/go#36416 Change-Id: Ifaa15a0777ea97e62c1477fb33911636b13e073e Reviewed-on: https://go-review.googlesource.com/c/tools/+/213458 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com>
@Wingboy-Jim2: This will work as you expect in Leaving this issue open, as the fix should still be made in |
Change https://golang.org/cl/202277 mentions this issue: |
As discussed on the above CL, the additional work-arounds in go/packages are not worth the complexity, particularly since this issue has now been addressed in |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I started up VS Code on a directory. There was a single package (main) spread across multiple files. There was no go.mod file.
When looking at a file VS Code displayed multiple undeclared name errors for the current file.
Although true that the current file does not declare that names these names were declared in other files in the same directory.
Exiting VS Code and doing a go build in the directory builds with no errors. But entering back into VS Code shows errors for any file that I view in the editor.
What did you expect to see?
No errors
What did you see instead?
Errors for undeclared names. I get the same errors when do a gopls check on any file.
Creating a go.mod file addresses this, even if I do a gopls check on a single file.
First submitted this as a microsoft/vscode-go#2967 before I determined that gopls seemed to be the involved.
The text was updated successfully, but these errors were encountered: