x/tools/gopls: picks random import path not in go.mod when wanted import path for package is in go.mod #61208
Labels
gopls/imports
gopls
Issues related to the Go language server, gopls.
NeedsFix
The path to resolution is known, but the work has not been done.
Tools
This label describes issues relating to any tools in the x/tools repository.
Milestone
What version of Go, VS Code & VS Code Go extension are you using?
Version Information
go version
to get version of Go from the VS Code integrated terminal.go version go1.20.5 darwin/arm64
gopls -v version
to get version of Gopls from the VS Code integrated terminal.golang.org/x/tools/gopls v0.12.4
code -v
orcode-insiders -v
to get version of VS Code or VS Code Insiders.1.79.2
v0.39.0
Go: Locate Configured Go Tools
command.Share the Go related settings you have added/edited
Run
Preferences: Open Settings (JSON)
command to open your settings.json file.Share all the settings with the
go.
or["go"]
orgopls
prefixes.Excerpt from settings.json
Describe the bug
When starting to use a new package in a Go source file, the plugin (automatically) adds an import path to an identically named package that is not available in my
go.mod
file. This happens even though my project is already using the package/import path I want in other files (and thus is already in mygo.mod
). That is, the plugin is not able to recognize an existing import path for the package, but instead appears to pick an import path at random.I would expect that the plugin would prioritize to use the import path of the package already available in
go.mod
.Steps to reproduce the behavior:
proto.Message
type."go.starlark.net/lib/proto"
grep -R 'go.starlark.net/lib/proto' *
and observe that the entire project makes no mention of this import path.grep -R 'google.golang.org/protobuf/proto' * | wc -l
and observe that the project is using this import path in 11 files.Screenshots or recordings
The text was updated successfully, but these errors were encountered: