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
Assignees
Milestone

Comments

@fhs
Copy link
Contributor

@fhs 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

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Jul 15, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.