-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: add a diagnostic (and quick-fix) when a package is outside of go.work #53880
Comments
Just for clarification: by "is excluded by go.work" do you mean that a Go module isn't listed in a |
@thedive I mean "a go.work is in use, and the current module is not used". You said "a So if I have a go.work using |
@findleyr yes, exactly, the "in a |
From in-person discussion, this can be achieved approximately as follows: In Server.checkForOrphanedFiles, where we generate the "No packages found" diagnostic, we need to determine if a
If these conditions hold, then we can suggest a quickfix to run We could go further and try to check whether the file would be excluded by build tags even if we use its module, but that is probably overkill. |
Change https://go.dev/cl/448695 mentions this issue: |
Change https://go.dev/cl/494675 mentions this issue: |
Fix some of the very misleading errors gopls produces when it can't find packages for a file. Try to diagnose _why_ a file is orphaned by the workspace, rather than just guess that it may be due to build constraints. Only put diagnostics on files that we can prove are excluded in some way. To achieve this, we need to be able to differentiate command-line-arguments packages that are standalone packages, so add a corresponding field on source.Metadata. Refactor/simplify some functions that operate on open files. In the future, we really should track overlays separately in the snapshot, but that is out-of-scope for now. Also make a minor fix for TestImplementationsOfError: I use $HOME/src as my development directory, so GOROOT/src is $HOME/src/go/src. For golang/go#53880 Change-Id: I8e9fa7d4f2c03ce3daaab7c6d119b4276ec6da79 Reviewed-on: https://go-review.googlesource.com/c/tools/+/494675 Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Change https://go.dev/cl/494738 mentions this issue: |
It can be very confusing when gopls does not function properly because a package is excluded by go.work.
We should provide a friendly error message, preferably as a diagnostic on the package name and/or module name, with a quick fix to add the module to go.work.
The text was updated successfully, but these errors were encountered: