Skip to content
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: missing unimported package candidates #35359

Closed
muirdm opened this issue Nov 4, 2019 · 5 comments
Closed

x/tools/gopls: missing unimported package candidates #35359

muirdm opened this issue Nov 4, 2019 · 5 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@muirdm
Copy link

muirdm commented Nov 4, 2019

Repro (assuming completeUnimported=true is configured):

  1. Create a new module with contents:
package main

func main() {
}
  1. Complete rand.. You should see suggestions from crypto/rand and math/rand.
  2. Select rand.Int from "crypto/rand"
  3. Delete line and save ("crypto/rand" import should disappear).
  4. Wait a second to make sure "crypto/rand" package handle gets GC'd 😉
  5. Complete rand. again. Now you only see untyped completions from "crypto/rand". I expected to see typed completions from "crypto/rand" and completions from "math/rand".

See https://youtu.be/VaOs1crVI4g

/cc @stamblerre @heschik

@gopherbot gopherbot added this to the Unreleased milestone Nov 4, 2019
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Nov 4, 2019
@gopherbot
Copy link

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.

@gopherbot gopherbot added the gopls Issues related to the Go language server, gopls. label Nov 4, 2019
@muirdm muirdm changed the title x/tools/gopls: missing unwanted imports x/tools/gopls: missing unimported package candidates Nov 4, 2019
@heschi heschi self-assigned this Nov 5, 2019
@heschi
Copy link
Contributor

heschi commented Nov 5, 2019

When I look at logs, I see a ton of "no file for" errors, which are coming from findFileInPackage in pkg.go. Will look tomorrow.

@heschi
Copy link
Contributor

heschi commented Nov 5, 2019

...I looked a little now. The problem is that findFileInPackage can't find anything for math/rand/rand.go because it's not in the package's dependencies any more. Annoying, since I had the package to start with when I called packageMembers.

@gopherbot
Copy link

Change https://golang.org/cl/205501 mentions this issue: internal/lsp/source: attach Package to completions when available

@gopherbot
Copy link

Change https://golang.org/cl/205658 mentions this issue: internal/lsp/source: attach Package to completions when available

gopherbot pushed a commit to golang/tools that referenced this issue Nov 6, 2019
Unimported completions now try to pull Packages from everywhere, not
just the transitive dependencies of the current package. That confused
the import formatting code, which only looked at deps. Pass the Package
along with the import suggestion, and use it when it's present.

Also change some error messages to be different for diagnostic purposes.

Fixes golang/go#35359.

Change-Id: Ia8ca923e46723e855ddd2da7611e6eb13c02bb4f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/205501
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
(cherry picked from commit 8185551)
Reviewed-on: https://go-review.googlesource.com/c/tools/+/205658
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
@golang golang locked and limited conversation to collaborators Nov 5, 2020
@rsc rsc unassigned heschi Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants