vscode-go
vscode-go copied to clipboard
coverage: "illegal argument" vscode error from Go //line directive
What version of Go, VS Code & VS Code Go extension are you using?
Version Information
-
Run
go versionto get version of Go from the VS Code integrated terminal. go version devel go1.20-d4ff25ac69 Thu Aug 25 11:40:57 2022 +0000 linux/amd64 -
Run
gopls -v versionto get version of Gopls from the VS Code integrated terminal.
Build info
golang.org/x/tools/gopls v0.9.4 golang.org/x/tools/gopls@(devel) github.com/BurntSushi/[email protected] h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0= github.com/google/[email protected] h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= github.com/sergi/[email protected] h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= golang.org/x/exp/[email protected] h1:7Xs2YCOpMlNqSQSmrrnhlzBXIE/bpMecZplbLePTJvE= golang.org/x/[email protected] h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s= golang.org/x/[email protected] h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw= golang.org/x/[email protected] h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s= golang.org/x/[email protected] h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/[email protected] h1:b68wxF4nfQjj1XTRHtjVjCximbhAwjztuzDEFGU+n9o= golang.org/x/[email protected] h1:BkeW9/QJhcigekDUPS9N9bIb0v7gPKKmLYeczVAqr2s= honnef.co/go/[email protected] h1:ytYb4rOqyp1TSa2EPvNVwtPQJctSELKaMyLfqNP4+34= mvdan.cc/[email protected] h1:avhhrOmv0IuvQVK7fvwV91oFSGAk5/6Po8GXTzICeu8= mvdan.cc/xurls/[email protected] h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc= go: devel go1.20-d4ff25ac69 Thu Aug 25 11:40:57 2022 +0000
- Run
code -vorcode-insiders -vto get version of VS Code or VS Code Insiders.- 1.69.1 b06ae3b2d2dbfe28bca3134cc6be65935cdfea6a x64
- Check your installed extensions to get the version of the VS Code Go extension
- v0.35.2
-
Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) >
Go: Locate Configured Go Toolscommand.
Checking configured tools.... GOBIN: undefined toolsGopath: gopath: /ssd2/go1 GOROOT: /ssd2/go.master PATH: /ssd2/go.master/bin:/ssd2/go1/bin:/ssd2/gobootstrap/bin:/usr/local/google/home/thanm/bin:/usr/lib/google-golang/bin:/usr/local/buildtools/java/jdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/ssd/gcc-trunk/cross/bin
go: /ssd2/go.master/bin/go: go version devel go1.20-d4ff25ac69 Thu Aug 25 11:40:57 2022 +0000 linux/amd64
gotests: not installed
gomodifytags: not installed
impl: not installed
goplay: not installed
dlv: /ssd2/go1/bin/dlv (version: (devel) built with go: go1.18-7c94355b73)
staticcheck: /ssd2/go1/bin/staticcheck (version: (devel) built with go: undefined)
gopls: /ssd2/go1/bin/gopls (version: (devel) built with go: go1.20-d4ff25ac69)
go env Workspace Folder (p): /ssd2/go1/src/github.com/thanm/nbt/cov-example/p GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/usr/local/google/home/thanm/.cache/go-build" GOENV="/usr/local/google/home/thanm/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/ssd2/go1/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/ssd2/go1" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/ssd2/go.master" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/ssd2/go.master/pkg/tool/linux_amd64" GOVCS="" GOVERSION="devel go1.20-d4ff25ac69 Thu Aug 25 11:40:57 2022 +0000" GCCGO="/ssd/gcc-trunk/cross/bin/gccgo" GOAMD64="v1" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="/ssd2/go1/src/github.com/thanm/nbt/cov-example/go.mod" GOWORK="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build748014552=/tmp/go-build -gno-record-gcc-switches"
Share the Go related settings you have added/edited
Haven't changed the go settings (as far as I know).
Describe the bug
This is a problem with editing a package whose source code has a "//line" directive, resulting in an unexpected error from vscode. Details below:
Steps to reproduce the behavior:
- download https://github.com/thanm/nbt.git
- git checkout 8471f630179370d381a9e2194c03f7538fe5a0f0
- cd to nbt/linedir
- code .
- bring up "blah.go" in the editor
- Select "Go: Toggle Test Coverage In Current Package"
This will result in this popup error:

The problematic construct in the package is in this function:
func Baz() int {
println(Foo(), Bar())
//line p.go:98989
if G == 101 {
return 3
}
println(Foo() + Bar())
return 432
}
Note the line directive. If you remove this, things work properly.
It looks like this error comes from VS Code itself, so we're producing incorrect position information somewhere.
The line number in question is large (98989); perhaps this overflows some VSCode limit?
@thanm thanks for pointing that out. This could also be a tool somewhere in the go test stack mishandling the line directive (compare golang/go#55043).
Needs investigation to see. Thanks for providing a reproducer.
Change https://go.dev/cl/447957 mentions this issue: src/goCover: ignore bogus-looking line/column data