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: picks random import path not in go.mod when wanted import path for package is in go.mod #61208

Open
meling opened this issue Jun 29, 2023 · 1 comment
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

Comments

@meling
Copy link

meling commented Jun 29, 2023

What version of Go, VS Code & VS Code Go extension are you using?

Version Information
  • Run go version to get version of Go from the VS Code integrated terminal.
    • go version go1.20.5 darwin/arm64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • golang.org/x/tools/gopls v0.12.4
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.79.2
  • Check your installed extensions to get the version of the VS Code Go extension
    • v0.39.0
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
Checking configured tools....
GOBIN: undefined
toolsGopath: 
gopath: /Users/meling/go
GOROOT: /opt/homebrew/Cellar/go/1.20.5/libexec
PATH: /opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Users/meling/.cargo/bin:/Users/meling/go/bin

	go:	/opt/homebrew/bin/go: go version go1.20.5 darwin/arm64

	gotests:	/Users/meling/go/bin/gotests	(version: v1.6.0 built with go: go1.20.3)
	gomodifytags:	/Users/meling/go/bin/gomodifytags	(version: v1.16.0 built with go: go1.20.3)
	impl:	/Users/meling/go/bin/impl	(version: v1.1.0 built with go: go1.20.3)
	goplay:	/Users/meling/go/bin/goplay	(version: v1.0.0 built with go: go1.20.3)
	dlv:	/Users/meling/go/bin/dlv	(version: v1.20.1 built with go: go1.20.3)
	golangci-lint:	/Users/meling/go/bin/golangci-lint	(version: v1.51.0 built with go: go1.20.3)
	gopls:	/Users/meling/go/bin/gopls	(version: v0.12.4 built with go: go1.20.5)

go env
Workspace Folder (hotstuff): /Users/meling/Team-UIS Dropbox/Hein Meling/work/hotstuff
	GO111MODULE=""
	GOARCH="arm64"
	GOBIN=""
	GOCACHE="/Users/meling/Library/Caches/go-build"
	GOENV="/Users/meling/Library/Application Support/go/env"
	GOEXE=""
	GOEXPERIMENT=""
	GOFLAGS=""
	GOHOSTARCH="arm64"
	GOHOSTOS="darwin"
	GOINSECURE=""
	GOMODCACHE="/Users/meling/go/pkg/mod"
	GONOPROXY=""
	GONOSUMDB=""
	GOOS="darwin"
	GOPATH="/Users/meling/go"
	GOPRIVATE=""
	GOPROXY="https://proxy.golang.org,direct"
	GOROOT="/opt/homebrew/Cellar/go/1.20.5/libexec"
	GOSUMDB="sum.golang.org"
	GOTMPDIR=""
	GOTOOLDIR="/opt/homebrew/Cellar/go/1.20.5/libexec/pkg/tool/darwin_arm64"
	GOVCS=""
	GOVERSION="go1.20.5"
	GCCGO="gccgo"
	AR="ar"
	CC="/opt/homebrew/bin/gcc-13"
	CXX="/opt/homebrew/bin/g++-13"
	CGO_ENABLED="1"
	GOMOD="/Users/meling/Team-UIS Dropbox/Hein Meling/work/hotstuff/go.mod"
	GOWORK=""
	CGO_CFLAGS="-O2 -g"
	CGO_CPPFLAGS=""
	CGO_CXXFLAGS="-O2 -g"
	CGO_FFLAGS="-O2 -g"
	CGO_LDFLAGS="-O2 -g"
	PKG_CONFIG="pkg-config"
	GOGCCFLAGS="-fPIC -arch arm64 -pthread -fmessage-length=0 -fdebug-prefix-map=/var/folders/gl/s8cqs8k12kdgvgplr56lz3q40000gn/T/go-build2039093197=/tmp/go-build -gno-record-gcc-switches -fno-common"

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"] or gopls prefixes.

Excerpt from settings.json
    "go.useLanguageServer": true,
    "go.languageServerFlags": [
        "-rpc.trace"
    ],
    "go.toolsManagement.autoUpdate": true,
    "go.toolsEnvVars": {
        "CXX": "/opt/homebrew/bin/g++-13",
        "CC": "/opt/homebrew/bin/gcc-13",
    },
    "gopls": {
        "build.standaloneTags": [
            "tools",
            "ignore"
        ],
        "formatting.gofumpt": true,
        "build.env": {
            "CXX": "/opt/homebrew/bin/g++-13",
            "CC": "/opt/homebrew/bin/gcc-13",
        },
        "verboseOutput": true
    },

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 my go.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:

  1. Write a new function that returns a proto.Message type.
  2. Save the file.
  3. Watch the import section be augmented with "go.starlark.net/lib/proto"
  4. Run grep -R 'go.starlark.net/lib/proto' * and observe that the entire project makes no mention of this import path.
  5. Run grep -R 'google.golang.org/protobuf/proto' * | wc -l and observe that the project is using this import path in 11 files.
  6. See screenshots below

Screenshots or recordings

Screenshot 2023-06-29 at 13 33 55 Screenshot 2023-06-29 at 13 33 19
@findleyr findleyr changed the title gopls: picks random import path not in go.mod when wanted import path for package is in go.mod x/tools/gopls: picks random import path not in go.mod when wanted import path for package is in go.mod Jul 6, 2023
@findleyr
Copy link
Contributor

findleyr commented Jul 6, 2023

Thanks, I am collecting issues related to poor gopls imports behavior.

Transferring to the Go issue tracker.

@findleyr findleyr transferred this issue from golang/vscode-go Jul 6, 2023
@findleyr findleyr added this to the gopls/v0.13.0 milestone Jul 6, 2023
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Jul 6, 2023
@findleyr findleyr modified the milestones: gopls/v0.14.0, gopls/v0.15.0 Oct 9, 2023
@findleyr findleyr modified the milestones: gopls/v0.15.0, gopls/v0.16.0 Dec 12, 2023
@joedian joedian added the NeedsFix The path to resolution is known, but the work has not been done. label Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.
Projects
None yet
Development

No branches or pull requests

4 participants