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 panics if a test file exists #33664

Closed
fhs opened this issue Aug 15, 2019 · 2 comments
Closed

x/tools/gopls: rename panics if a test file exists #33664

fhs opened this issue Aug 15, 2019 · 2 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls.
Milestone

Comments

@fhs
Copy link
Contributor

fhs commented Aug 15, 2019

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

$ go version
go version devel +61bb56ad63 Mon Aug 12 23:12:29 2019 +0000 linux/amd64
$ gopls version
golang.org/x/tools/cmd/gopls v0.1.3-cmd.gopls
    golang.org/x/tools@v0.0.0-20190814235402-ea4142463bf3 h1:MVK2S/Gc+FEEuMU3i5K19MikzZsXixt3eMCaX2mCOfY=

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

go env Output
$ go env | grep -v [private]
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/fhs/.cache/go-build"
GOENV="/home/fhs/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/fhs/go"
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/foo/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-build173386163=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Create an example module:

$ mkdir /tmp/foo
$ cd /tmp/foo
$ cat > main.go
package main

import "fmt"

func main() {
	foo := 42
	fmt.Println(foo)
}
$ echo 'package main' > main_test.go
$ go mod init example.com/foo

Add /tmp/foo to VSCode workspace and then try to rename variable foo to bar.

What did you expect to see?

Successful rename.

What did you see instead?

gopls crashes:

[Trace - 5:15:21 AM] Sending notification 'textDocument/rename' in 1ms.
Params: {"textDocument":{"uri":"file:///tmp/foo/main.go"},"position":{"line":5,"character":2},"newName":"bar"}


[Error - 5:15:21 AM] Request textDocument/rename failed.
  Message: method "textDocument/rename" did not reply
  Code: -32603 
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x40 pc=0x797a72]

goroutine 1402 [running]:
golang.org/x/tools/internal/lsp/source.forEachLexicalRef(0xbf6040, 0xc002506a80, 0x0, 0x0, 0xc015a0, 0xc001d52cd0, 0xc0024d7000, 0xc0002e8700)
	/home/fhs/go/pkg/mod/golang.org/x/tools@v0.0.0-20190814235402-ea4142463bf3/internal/lsp/source/rename_check.go:334 +0x112
golang.org/x/tools/internal/lsp/source.(*renamer).checkInLexicalScope(0xc001a464d0, 0xc015a0, 0xc001d52cd0, 0x0, 0x0)
	/home/fhs/go/pkg/mod/golang.org/x/tools@v0.0.0-20190814235402-ea4142463bf3/internal/lsp/source/rename_check.go:214 +0xe8
golang.org/x/tools/internal/lsp/source.(*renamer).checkInLocalScope(0xc001a464d0, 0xc015a0, 0xc001d52cd0)
	/home/fhs/go/pkg/mod/golang.org/x/tools@v0.0.0-20190814235402-ea4142463bf3/internal/lsp/source/rename_check.go:144 +0x98
golang.org/x/tools/internal/lsp/source.(*renamer).check(0xc001a464d0, 0xc015a0, 0xc001d52cd0)
	/home/fhs/go/pkg/mod/golang.org/x/tools@v0.0.0-20190814235402-ea4142463bf3/internal/lsp/source/rename_check.go:49 +0x1e7
golang.org/x/tools/internal/lsp/source.(*IdentifierInfo).Rename(0xc0024fe5b0, 0xbf6040, 0xc002506a80, 0xc00230cd10, 0x3, 0x0, 0x0, 0x0)
	/home/fhs/go/pkg/mod/golang.org/x/tools@v0.0.0-20190814235402-ea4142463bf3/internal/lsp/source/rename.go:82 +0x4af
golang.org/x/tools/internal/lsp.(*Server).rename(0xc00017b9a0, 0xbf6040, 0xc00251fa10, 0xc0025068a0, 0x0, 0x0, 0xc001a46370)
	/home/fhs/go/pkg/mod/golang.org/x/tools@v0.0.0-20190814235402-ea4142463bf3/internal/lsp/rename.go:34 +0x281
golang.org/x/tools/internal/lsp.(*Server).Rename(0xc00017b9a0, 0xbf6040, 0xc00251fa10, 0xc0025068a0, 0xc0025068a0, 0x0, 0x0)
	/home/fhs/go/pkg/mod/golang.org/x/tools@v0.0.0-20190814235402-ea4142463bf3/internal/lsp/server.go:253 +0x49
golang.org/x/tools/internal/lsp/protocol.serverHandler.Deliver(0xc07280, 0xc00017b9a0, 0xbf6040, 0xc00251fa10, 0xc0024d2bc0, 0xc00251fa00, 0xc0024a8b90)
	/home/fhs/go/pkg/mod/golang.org/x/tools@v0.0.0-20190814235402-ea4142463bf3/internal/lsp/protocol/tsserver.go:466 +0xf47
golang.org/x/tools/internal/jsonrpc2.(*Conn).Run.func1(0xc001ec43c0, 0xc0024d2bc0, 0xc0000b7c80, 0xbf6040, 0xc00251fa10, 0x0, 0x0, 0xc0024f44b0)
	/home/fhs/go/pkg/mod/golang.org/x/tools@v0.0.0-20190814235402-ea4142463bf3/internal/jsonrpc2/jsonrpc2.go:370 +0x170
created by golang.org/x/tools/internal/jsonrpc2.(*Conn).Run
	/home/fhs/go/pkg/mod/golang.org/x/tools@v0.0.0-20190814235402-ea4142463bf3/internal/jsonrpc2/jsonrpc2.go:354 +0x86a
[Info  - 5:15:21 AM] Connection to server got closed. Server will restart.

Note: rename is successful if you remove main_test.go.

@gopherbot gopherbot added this to the Unreleased milestone Aug 15, 2019
@gopherbot gopherbot added the gopls Issues related to the Go language server, gopls. label Aug 15, 2019
@suzmue
Copy link
Contributor

suzmue commented Aug 15, 2019

Thanks for the repro! Found the bug and am sending a fix.

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/190399 mentions this issue: internal/lsp: fix bug to add all packages to map for checking

@golang golang locked and limited conversation to collaborators Aug 14, 2020
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.
Projects
None yet
Development

No branches or pull requests

3 participants