go
go copied to clipboard
goimports: auto imports does not work in Go Workspace with vendoring enabled
Go version
go version go1.22.0 windows/amd64
Output of go env
in your module/workspace:
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Owner\AppData\Local\go-build
set GOENV=C:\Users\Owner\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\Owner\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Owner\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.22.0
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=F:\work\go\go-workspace-vendoring\go.mod
set GOWORK=F:\work\go\go-workspace-vendoring\go.work
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\Owner\AppData\Local\Temp\go-build1842545717=/tmp/go-build -gno-record-gcc-switches
What did you do?
I made a repro.
At repository root, Run goimports main.go
.
What did you see happen?
No imports were added.
What did you expect to see?
import "github.com/tamayika/module1"
should be added.
If I delete vendor directory, it works. This is also happen in gopls because it used goimports internally. It show below error.
[Info - 4:10:57 PM] 2024/02/16 16:10:57 background refresh finished after 35.9847ms: err: exit status 1: stderr: go: can't match module patterns using the vendor directory
(Use -mod=mod or -mod=readonly to bypass.)
This line throws error. https://github.com/golang/tools/blob/master/internal/imports/mod.go#L140. I think goimports lacks workspace vendoring support.
@golang/tools-team
Change https://go.dev/cl/572675 mentions this issue: cmd/goimports: support workspace vendoring