x/tools/gopls: data corruption on save
Closed this issue · 2 comments
josharian commented
gopls version
$ gopls -v version
Build info
----------
golang.org/x/tools/gopls v0.11.0
golang.org/x/tools/gopls@v0.11.0 h1:/nvKHdTtePQmrv9XN3gIUN9MOdUrKzO/dcqgbG6x8EY=
github.com/BurntSushi/toml@v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
github.com/google/go-cmp@v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
golang.org/x/exp@v0.0.0-20221031165847-c99f073a8326 h1:QfTh0HpN6hlw6D3vu8DAwC8pBIwikq0AI1evdm+FksE=
golang.org/x/exp/typeparams@v0.0.0-20221031165847-c99f073a8326 h1:fl8k2zg28yA23264d82M4dp+YlJ3ngDcpuB1bewkQi4=
golang.org/x/mod@v0.7.0 h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA=
golang.org/x/sync@v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sys@v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
golang.org/x/text@v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
golang.org/x/tools@v0.3.1-0.20221213193459-ca17b2c27ca8 h1:7/HkGkN/2ktghBCSRRgp31wAww4syfsW52tj7yirjWk=
golang.org/x/vuln@v0.0.0-20221109205719-3af8368ee4fe h1:qptQiQwEpETwDiz85LKtChqif9xhVkAm8Nhxs0xnTww=
honnef.co/go/tools@v0.3.3 h1:oDx7VAwstgpYpb3wv0oxiZlxY+foCpRAwY7Vk6XpAgA=
mvdan.cc/gofumpt@v0.4.0 h1:JVf4NN1mIpHogBj7ABpgOyZc65/UUOkKQFkoURsz4MM=
mvdan.cc/xurls/v2@v2.4.0 h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc=
go: go1.20
go env
$ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN="/Users/josh/bin"
GOCACHE="/Users/josh/Library/Caches/go-build"
GOENV="/Users/josh/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/josh/pkg/mod"
GONOPROXY="github.com/canopyclimate/www"
GONOSUMDB="github.com/canopyclimate/www"
GOOS="darwin"
GOPATH="/Users/josh"
GOPRIVATE="github.com/canopyclimate/www"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/josh/go/1.20"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/josh/go/1.20/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.20.3"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/73/xx0jgm0j5ws5lqb8qngnqwc40000gn/T/go-build3159536453=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
Put this code into a file (not using VSCode):
package main
func Match(data []byte) int {
//line :1
var idx = ^uint(0)
_ = idx
return -1
}Open in VSCode. Save (with formatting).
What did you expect to see?
No changes.
What did you see instead?
pge m:ain
func Match(data []byte) int {
//line :1
var idx = ^uint(0)
_ = idx
return -1
}This doesn't reproduce from the command line using gofmt or gofumpt or goimports.
Editor and settings
Some possibly(?) relevant snippets:
"go.useLanguageServer": true,
"gopls": {
"formatting.gofumpt": true,
},
"editor.formatOnSave": true,
"[go]": {
"editor.defaultFormatter": "golang.go"
},
"go.formatTool": "goimports",
findleyr commented
Thanks for the report. This is already fixed at master (coincidentally, as we made several changes to handling of line directives).
I'll leave this open and add it to the v0.12.0 milestone to ensure we include a test for this bug.
gopherbot commented
Change https://go.dev/cl/490315 mentions this issue: gopls/internal/regtest/marker: add a test case for issue #59554