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
Assignees
Labels
Milestone

Comments

@muirdm
Copy link

@muirdm 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 label Nov 4, 2019
@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Nov 4, 2019

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 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
@heschik heschik self-assigned this Nov 5, 2019
@heschik

This comment has been minimized.

Copy link
Contributor

@heschik heschik 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.

@heschik

This comment has been minimized.

Copy link
Contributor

@heschik heschik 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

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Nov 5, 2019

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

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Nov 6, 2019

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.