Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/gopls: rename responds with unsorted edits #33123

Closed
fhs opened this issue Jul 15, 2019 · 1 comment
Closed

x/tools/gopls: rename responds with unsorted edits #33123

fhs opened this issue Jul 15, 2019 · 1 comment
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@fhs
Copy link
Contributor

fhs commented Jul 15, 2019

What version of Go are you using (go version)?

$ go version
go version devel +21f5484006 Fri Jul 12 21:19:51 2019 +0000 linux/amd64
$ gopls version
golang.org/x/tools/cmd/gopls v0.1.3-cmd.gopls
    golang.org/x/tools@v0.0.0-20190715044752-607ca053a137 h1:66qBt03VVO7qHSq0eBAYy9iD1y2EbXU09A+F5dZ0j8s=

Does this issue reproduce with the latest release?

Yes, reproduces with gopls v0.1.3

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/fhs/.cache/go-build"
GOENV="/home/fhs/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/fhs/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/big/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/big/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/tmp/renametest/go.mod"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build157526866=/tmp/go-build -gno-record-gcc-switches"

What did you do?

$ mkdir /tmp/renametest
$ cd /tmp/renametest
$ go mod init example.com/renametest
go: creating new go.mod: module example.com/renametest
$ cat > main.go
package main

// foo is awesome.
func foo() {
}

func main() {
	foo()
}
$

Rename foo to fooBar.

What did you expect to see?

package main

// fooBar is awesome.
func fooBar() {
}

func main() {
	fooBar()
}

What did you see instead?

package main

// fooBar is awesome.
fufooBarfoo() {
}

func main() {
	fooBar()
}

This is happening because the golpls sends unsorted text edits (line 3 edit appears before line 2 edit) and I'm applying the edits in reverse order as documented in the integrator FAQ:

[Trace - 4:08:14 PM] Received response 'textDocument/rename - (3)' in 0ms.
Params: {"changes":{"file:///tmp/renametest/main.go":[{"range":{"start":{"line":3,"character":5},"end":{"line":3,"character":8}},"newText":"fooBar"},{"range":{"start":{"line":2,"character":3},"end":{"line":2,"character":6}},"newText":"fooBar"},{"range":{"start":{"line":7,"character":1},"end":{"line":7,"character":4}},"newText":"fooBar"}]}}

I'm using acme-lsp, but you may be able to reproduce the bug with govim because I got the idea of applying edits in reverse order from @myitcv.

@gopherbot gopherbot added this to the Unreleased milestone Jul 15, 2019
@gopherbot gopherbot added the gopls Issues related to the Go language server, gopls. label Jul 15, 2019
@stamblerre stamblerre added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 15, 2019
@gopherbot
Copy link

Change https://golang.org/cl/186258 mentions this issue: internal/lsp: sort rename results

@golang golang locked and limited conversation to collaborators Jul 14, 2020
@rsc rsc unassigned suzmue Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants