Skip to content

x/tools/gopls: data corruption on save #59554

Closed
@josharian

Description

@josharian

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",

Activity

added
ToolsThis label describes issues relating to any tools in the x/tools repository.
goplsIssues related to the Go language server, gopls.
on Apr 11, 2023
added this to the Unreleased milestone on Apr 11, 2023
findleyr

findleyr commented on Apr 11, 2023

@findleyr
Member

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

gopherbot commented on Apr 28, 2023

@gopherbot
Contributor

Change https://go.dev/cl/490315 mentions this issue: gopls/internal/regtest/marker: add a test case for issue #59554

locked and limited conversation to collaborators on Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @josharian@gopherbot@findleyr

        Issue actions

          x/tools/gopls: data corruption on save · Issue #59554 · golang/go