Skip to content

x/tools/gopls: import errors when using go.work replace directives #66425

Closed
@jonbarrow

Description

@jonbarrow

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.21.3 linux/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
Build info
----------
golang.org/x/tools/gopls v0.15.2
    golang.org/x/tools/[email protected] h1:4JKt4inO8JaFW3l/Fh9X1k/5JQn+iUOpdc4/Lpi0mOs=
    github.com/BurntSushi/[email protected] h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
    github.com/google/[email protected] h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
    golang.org/x/exp/[email protected] h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=
    golang.org/x/[email protected] h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8=
    golang.org/x/[email protected] h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
    golang.org/x/[email protected] h1:vcVnuftN4J4UKLRcgetjzfU9FjjgXUUYUc3JhFplgV4=
    golang.org/x/[email protected] h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
    golang.org/x/[email protected] h1:No0LMXYFkp3j4oEsPdtY8LUQz33gu79Rm9DE+izMeGQ=
    golang.org/x/[email protected] h1:KUas02EjQK5LTuIx1OylBQdKKZ9jeugs+HiqO5HormU=
    honnef.co/go/[email protected] h1:oFEHCKeID7to/3autwsWfnuv69j3NsfcXbvJKuIcep8=
    mvdan.cc/[email protected] h1:G3QvahNDmpD+Aek/bNOLrFR2XC6ZAdo62dZu65gmwGo=
    mvdan.cc/xurls/[email protected] h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=
go: go1.21.3
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
1.85.2
8b3775030ed1a69b13e4f4c628c612102e30a681
x64

Though this happens on all tried versions, from 1.80 to 1.87

  • Check your installed extensions to get the version of the VS Code Go extension
    • v0.41.2
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
# Tools Configuration


## Environment

GOBIN: undefined
toolsGopath: 
gopath: /home/jon/go
GOROOT: /usr/local/go
PATH: /home/jon/.local/share/pnpm:/home/jon/software:/home/jon/gems/bin:/opt/devkitpro/tools/bin:/home/jon/.nvm/versions/node/v21.6.2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/usr/local/go/bin:/opt/ghidra:/home/jon/go/bin:/home/jon/software/grpc/cmake/build

## Tools

	go:	/usr/local/go/bin/go: go version go1.21.3 linux/amd64

	gopls:	/home/jon/go/bin/gopls	(version: v0.15.2 built with go: go1.21.3)
	gotests:	/home/jon/go/bin/gotests	(version: v1.6.0 built with go: go1.21.3)
	gomodifytags:	/home/jon/go/bin/gomodifytags	(version: v1.16.0 built with go: go1.21.3)
	impl:	/home/jon/go/bin/impl	(version: v1.1.0 built with go: go1.21.3)
	goplay:	/home/jon/go/bin/goplay	(version: v1.0.0 built with go: go1.21.3)
	dlv:	/home/jon/go/bin/dlv	(version: v1.21.1 built with go: go1.21.3)
	golangci-lint:	/home/jon/go/bin/golangci-lint	(version: (devel) built with go: go1.21.3)

## Go env

Workspace Folder (nex-go-rewrite): /home/jon/pretendo/nex-go-rewrite

	GO111MODULE=''
	GOARCH='amd64'
	GOBIN=''
	GOCACHE='/home/jon/.cache/go-build'
	GOENV='/home/jon/.config/go/env'
	GOEXE=''
	GOEXPERIMENT=''
	GOFLAGS=''
	GOHOSTARCH='amd64'
	GOHOSTOS='linux'
	GOINSECURE=''
	GOMODCACHE='/home/jon/go/pkg/mod'
	GONOPROXY=''
	GONOSUMDB=''
	GOOS='linux'
	GOPATH='/home/jon/go'
	GOPRIVATE=''
	GOPROXY='direct'
	GOROOT='/usr/local/go'
	GOSUMDB='sum.golang.org'
	GOTMPDIR=''
	GOTOOLCHAIN='auto'
	GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
	GOVCS=''
	GOVERSION='go1.21.3'
	GCCGO='gccgo'
	GOAMD64='v1'
	AR='ar'
	CC='gcc'
	CXX='g++'
	CGO_ENABLED='1'
	GOMOD='/home/jon/pretendo/nex-go-rewrite/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 -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build371863881=/tmp/go-build -gno-record-gcc-switches'
	
Workspace Folder (nex-protocols-go): /home/jon/pretendo/nex-protocols-go

	GO111MODULE=''
	GOARCH='amd64'
	GOBIN=''
	GOCACHE='/home/jon/.cache/go-build'
	GOENV='/home/jon/.config/go/env'
	GOEXE=''
	GOEXPERIMENT=''
	GOFLAGS=''
	GOHOSTARCH='amd64'
	GOHOSTOS='linux'
	GOINSECURE=''
	GOMODCACHE='/home/jon/go/pkg/mod'
	GONOPROXY=''
	GONOSUMDB=''
	GOOS='linux'
	GOPATH='/home/jon/go'
	GOPRIVATE=''
	GOPROXY='direct'
	GOROOT='/usr/local/go'
	GOSUMDB='sum.golang.org'
	GOTMPDIR=''
	GOTOOLCHAIN='auto'
	GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
	GOVCS=''
	GOVERSION='go1.21.3'
	GCCGO='gccgo'
	GOAMD64='v1'
	AR='ar'
	CC='gcc'
	CXX='g++'
	CGO_ENABLED='1'
	GOMOD='/home/jon/pretendo/nex-protocols-go/go.mod'
	GOWORK='/home/jon/pretendo/nex-protocols-go/go.work'
	CGO_CFLAGS='-O2 -g'
	CGO_CPPFLAGS=''
	CGO_CXXFLAGS='-O2 -g'
	CGO_FFLAGS='-O2 -g'
	CGO_LDFLAGS='-O2 -g'
	PKG_CONFIG='pkg-config'
	GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build152155767=/tmp/go-build -gno-record-gcc-switches'
	

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.

  • "go.toolsManagement.autoUpdate": true

Describe the bug

replace directive seems to be ignored in go.work file. Failing to load the correct local package. Only occurs in VS Code, go vet reports no issues.

This behavior was working up until recently. I do not have an exact time/version this stopped working, as it has been a few days since I touched these modules.

Steps to reproduce the behavior:

  1. Create 2 modules
  2. Add both to a VS Code workspace
  3. Create a go.work in ModuleA
  4. Set a replace directive in the go.work to point to ModuleB
  5. ModuleB fails to be loaded in VS Code

Screenshots or recordings

go.work contents:

go 1.21

use .

replace (
	github.com/PretendoNetwork/nex-go => ../nex-go-rewrite
)

Broken import/wrong package being referenced leading to many errors:
Screenshot from 2024-03-16 19-23-19

The local package does exist:
Screenshot from 2024-03-16 19-24-37

go vet command showing no errors (issue is only within VS Code):
Screenshot from 2024-03-16 19-25-24

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions