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: imports older modules #67345

Open
jzelinskie opened this issue May 13, 2024 · 2 comments
Open

x/tools/gopls: imports older modules #67345

jzelinskie opened this issue May 13, 2024 · 2 comments
Assignees
Labels
gopls/imports 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

@jzelinskie
Copy link
Contributor

jzelinskie commented May 13, 2024

Go version

go version go1.22.2 darwin/arm64, golang.org/x/tools/gopls v0.15.2

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/jzelinskie/Library/Caches/go-build'
GOENV='/Users/jzelinskie/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/jzelinskie/.local/share/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/jzelinskie/.local/share/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.22.2/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.22.2/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.2'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-L/opt/homebrew/lib'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/y8/7684dpln6fx116tgj4gb_ff00000gn/T/go-build3939956594=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

  1. Import a module that contains both a v2 and v1 version (e.g. import "github.com/jzelinskie/cobrautil/v2/cobraotel").
  2. Use another package from that module
  3. Run gopls/goimports to add the missing module

I'm not fully sure these are the minimum steps to reproduce, but I believe so. It might have to do with that's in your module cache, too.

I've had this cause issues in production because it slipped past code review because of how dependent folks are on for import tooling and linters on imports -- humans barely look at them.

What did you see happen?

The v1 module is imported

import (
	"github.com/jzelinskie/cobrautil"
	"github.com/jzelinskie/cobrautil/v2/cobraotel"
)

What did you expect to see?

The v2 module should be imported because it's already being used:

import (
	"github.com/jzelinskie/cobrautil/v2"
	"github.com/jzelinskie/cobrautil/v2/cobraotel"
)
@gopherbot gopherbot added the gopls Issues related to the Go language server, gopls. label May 13, 2024
@seankhliao seankhliao changed the title gopls/goimports: imports older modules x/tools/gopls: imports older modules May 13, 2024
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label May 13, 2024
@gopherbot gopherbot added this to the Unreleased milestone May 13, 2024
@adonovan adonovan modified the milestones: Unreleased, gopls/v0.16.0 May 13, 2024
@findleyr
Copy link
Contributor

CC @pjweinb

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. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants