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: inaccurate functionality for import with package name mismatching its path #51411

Open
findleyr opened this issue Mar 1, 2022 · 6 comments
Labels
gopls/completion gopls Tools WaitingForInfo
Milestone

Comments

@findleyr
Copy link
Contributor

@findleyr findleyr commented Mar 1, 2022

Reported in slack: gopls offers inaccurate functionality when importing github.com/wagslane/go-rabbitmq, which has the package name "rabbitmq". Completion is inaccurate, and import statements get removed on save:

image

@hyangah points out that this only happens when the module is not yet required by the go.mod. This is therefore probably a chicken-and-egg problem, but one that can be quite confusing for our users.

@findleyr findleyr added this to the gopls/on-deck milestone Mar 1, 2022
@hyangah
Copy link
Contributor

@hyangah hyangah commented Mar 1, 2022

@hyangah points out that this only happens when the module is not yet required by the go.mod. This is therefore probably a chicken-and-egg problem, but one that can be quite confusing for our users.

I was late in reading the slack - more confusion: the user reported that the user's code builds and there is no vet error. If the module wasn't required in the go.mod file, build and vet couldn't be successful. So, I am not sure if the user is seeing the same problem I observed. 🤔

@gopherbot gopherbot added Tools gopls labels Mar 1, 2022
@KoduIsGreat
Copy link

@KoduIsGreat KoduIsGreat commented Mar 1, 2022

@hyangah, @findleyr Hi, I'm the user that reported this issue in slack.
to clarify, the package is required in the go.mod.

To me it seems like gopls is using the ending segment of the import path rather than the declared package identifier.

@findleyr findleyr changed the title x/tools/gopls: inaccurate functionality for mismatching package name in unrequired module x/tools/gopls: inaccurate functionality for import with package name mismatching its path Mar 1, 2022
@findleyr
Copy link
Contributor Author

@findleyr findleyr commented Mar 1, 2022

@KoduIsGreat thank you for clarifying. I've updated the issue accordingly.

@muirdm
Copy link

@muirdm muirdm commented Apr 24, 2022

I couldn't reproduce this. I tried various things but only ever saw completions for "rabbitmq" (never "go-rabbitmq"), which added the proper import and overall worked as expected. Are you certain that completion was coming from gopls?

AFAIK the unimported package completions first look at other imports in your workspace taking in to account declared package name, otherwise falling back to searching GOMODCACHE which also takes in to account declared package name by parsing a single file in each directory.

@KoduIsGreat
Copy link

@KoduIsGreat KoduIsGreat commented Apr 25, 2022

If the completion wasn't coming from gopls, what else would it be coming from.

@muirdm
Copy link

@muirdm muirdm commented Apr 25, 2022

I dunno, some other VS Code integrated tool. Anyway, can you give steps to reproduce?

@suzmue suzmue added the gopls/completion label May 10, 2022
@findleyr findleyr added the WaitingForInfo label May 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls/completion gopls Tools WaitingForInfo
Projects
None yet
Development

No branches or pull requests

6 participants