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: FindFileInPackage nil pointer dereference #38100

Closed
minight opened this issue Mar 27, 2020 · 12 comments
Closed

x/tools/gopls: FindFileInPackage nil pointer dereference #38100

minight opened this issue Mar 27, 2020 · 12 comments
Labels
Milestone

Comments

@minight
Copy link

@minight minight commented Mar 27, 2020

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

$ go version
go version go1.14 linux/amd64 

$ gopls version
golang.org/x/tools/gopls master
    golang.org/x/tools/gopls@v0.1.8-0.20200326210457-5d86d385bf88 h1:VHwe8L5z49UodPQ00s8OuYq5xk8LjagpydtFF7m+JCo=

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/sean/.cache/go-build"
GOENV="/home/sean/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/sean/.go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/tmp/vimtest/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-build567811365=/tmp/go-build -gno-record-gcc-switches"

What did you do?

https://play.golang.org/p/SrULcmi-Xbb

Hovering over b.Baz in test.go will cause gopls to panic and crash.

bar.pb.go was generated with

#!/bin/bash
service="./pkg/bar/pb"
protoc \
    -I="${service}" \
    -I=. \
    -I="$GOPATH/src" \
    -I="$GOPATH/src/github.com/gogo/protobuf/types" \
    -I="$GOPATH/src/github.com/gogo/protobuf/gogoproto" \
    -I="$GOPATH/src/github.com/gogo/protobuf/protobuf" \
    --gogoslick_out=paths=source_relative,\
Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/empty.proto=github.com/gogo/protobuf/types,\
Mgoogle/api/annotations.proto=github.com/gogo/googleapis/google/api,\
Mgoogle/protobuf/field_mask.proto=github.com/gogo/protobuf/types:\
"${service}/" \
    ./"${service}"/*.proto
===== sent =====
Content-Length: 216

{"method": "textDocument/references", "jsonrpc": "2.0", "id": 5, "params": {"context": {"includeDeclaration": true}, "textDocument": {"uri": "file:///tmp/vimtest/test.go"}, "position": {"character": 10, "line": 11}}}
===== received =====
Content-Length: 162

{"jsonrpc":"2.0","result":[{"uri":"file:///tmp/vimtest/pkg/bar/pb/bar.pb.go","range":{"start":{"line":35,"character":1},"end":{"line":35,"character":4}}}],"id":4}
===== sent =====
Content-Length: 182

{"method": "textDocument/hover", "jsonrpc": "2.0", "id": 6, "params": {"textDocument": {"uri": "file:///tmp/vimtest/pkg/bar/pb/bar.pb.go"}, "position": {"character": 1, "line": 35}}}
===== received =====
Content-Length: 121

{"jsonrpc":"2.0","error":{"code":-32603,"message":"method \"textDocument/references\" did not reply","data":null},"id":5}
===== stderr =====
panic: runtime error: invalid memory address or nil pointer dereference
===== stderr =====
[signal SIGSEGV: segmentation violation code=0x1 addr=0x60 pc=0x7d4518]
===== stderr =====
===== stderr =====
goroutine 2409 [running]:
===== stderr =====
golang.org/x/tools/internal/lsp/source.FindFileInPackage(0x0, 0x0, 0xc003b65140, 0x28, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/source/util.go:715 +0x108
===== stderr =====
golang.org/x/tools/internal/lsp/source.findMapperInPackage(0xe49ce0, 0xc00039c000, 0x0, 0x0, 0xc003b65140, 0x28, 0x24, 0x2, 0xc00166b320)
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/source/util.go:687 +0x15e
===== stderr =====
golang.org/x/tools/internal/lsp/source.posToMappedRange(0xe49ce0, 0xc00039c000, 0x0, 0x0, 0x483, 0x486, 0x0, 0x0, 0x0, 0x0, ...)
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/source/util.go:205 +0x15b
===== stderr =====
golang.org/x/tools/internal/lsp/source.nameToMappedRange(...)
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/source/util.go:200
===== stderr =====
golang.org/x/tools/internal/lsp/source.objToMappedRange(0xe49ce0, 0xc00039c000, 0x0, 0x0, 0xe4a280, 0xc003465bd0, 0x0, 0x0, 0x0, 0x0, ...)
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/source/util.go:196 +0x11a
===== stderr =====
golang.org/x/tools/internal/lsp/source.References(0xe382e0, 0xc00313f5f0, 0xe49c40, 0xc000474150, 0xe36b60, 0xc000ac49c0, 0x4026000000000000, 0x4024000000000000, 0xc00065fb01, 0x0, ...)
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/source/references.go:50 +0xe3b
===== stderr =====
golang.org/x/tools/internal/lsp.(*Server).references(0xc00011e780, 0xe382e0, 0xc00329f140, 0xc0044f60f0, 0xc0044f60f0, 0x0, 0x0, 0x0, 0xc002907290)
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/references.go:19 +0xe7
===== stderr =====
golang.org/x/tools/internal/lsp.(*Server).References(0xc00011e780, 0xe382e0, 0xc00329f140, 0xc0044f60f0, 0xc0044f60f0, 0x0, 0x0, 0x0, 0x0)
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/server_gen.go:144 +0x4d
===== stderr =====
golang.org/x/tools/internal/lsp/protocol.serverHandler.Deliver(0xe52160, 0xc00011e780, 0xe382e0, 0xc00329f140, 0xc002df8c80, 0x1372900, 0x1370000)
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/protocol/tsserver.go:377 +0x251f
===== stderr =====
golang.org/x/tools/internal/jsonrpc2.(*Conn).Run.func1(0xc0032174a0, 0xc002df8c80, 0xc000120550, 0xe382e0, 0xc00329f140, 0x0, 0x0, 0xc003540860)
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/jsonrpc2/jsonrpc2.go:371 +0x160
===== stderr =====
created by golang.org/x/tools/internal/jsonrpc2.(*Conn).Run
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/jsonrpc2/jsonrpc2.go:355 +0x850

What did you expect to see?

gopls not to panic. Vim-go to highlight all references to the same variable.

What did you see instead?

gopls panic

@gopherbot gopherbot added this to the Unreleased milestone Mar 27, 2020
@gopherbot
Copy link

@gopherbot gopherbot commented Mar 27, 2020

Thank you for filing a gopls issue! Please take a look at the Troubleshooting guide, and make sure that you have provided all of the relevant information here.

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Mar 27, 2020

Can you please share your full gopls logs for this? I am not able to reproduce the crash, and it implies that we are calling FindFileInPkg on a nil package, which should be impossible. gopls -rpc.trace -v check path/to/file.go may also provide some useful information.

@minight
Copy link
Author

@minight minight commented Mar 27, 2020

Directory structure:

.
├── gen-proto.sh
├── go.mod
├── pkg
│   └── bar
│       ├── bar.go
│       └── pb
│           ├── bar.pb.go
│           └── bar.proto
└── test.go

3 directories, 6 files

$ gopls -rpc.trace -v check ./test.go
2020/03/27 11:41:18 Info:2020/03/27 11:41:18 Build info
----------
golang.org/x/tools/gopls master
    golang.org/x/tools/gopls@v0.1.8-0.20200326210457-5d86d385bf88 h1:VHwe8L5z49UodPQ00s8OuYq5xk8LjagpydtFF7m+JCo=
    github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/mod@v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=
    golang.org/x/sync@v0.0.0-20200317015054-43a5402ce75a h1:WXEvlFVvvGxCJLG6REjsT03iWnKLEWinaScsxF2Vm2o=
    golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88 h1:F7fM2kxXfuWw820fa+MMCCLH6hmYe+jtLnZpwoiLK4Q=
    golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
    honnef.co/go/tools@v0.0.1-2020.1.3 h1:sXmLre5bzIR6ypkjXCDI3jHPssRhc8KD/Ome589sc3U=
    mvdan.cc/xurls/v2@v2.1.0 h1:KaMb5GLhlcSX+e+qhbRJODnUUBvlw01jt4yrjFIHAuA=

Go info
-------
go version go1.14 linux/amd64

2020/03/27 11:41:18 Info:2020/03/27 11:41:18 go env for /tmp/vimtest
(valid build configuration = true)
(build flags: [-modfile=/tmp/go.vimtest.650432255.mod])
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/sean/.cache/go-build"
GOENV="/home/sean/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/sean/.go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/tmp/vimtest/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-build677954172=/tmp/go-build -gno-record-gcc-switches"
2020/03/27 11:41:18 Info:2020/03/27 11:41:18 go/packages.Load
	snapshot=0
	directory="/tmp/vimtest"
	query=["./..." "builtin"]
	packages=5

gopls logs

===== sent =====
Content-Length: 455

{"method": "initialize", "jsonrpc": "2.0", "id": 1, "params": {"rootUri": "file:///tmp/vimtest", "capabilities": {"workspace": {"workspaceFolders": true, "configuration": true, "didChangeConfiguration": {"dynamicRegistration": true}}, "textDocument": {"completion": {"completionItem": {"snippetSupport": false}}, "hover": {"contentFormat": ["plaintext"]}}}, "processId": 1018, "workspaceFolders": [{"uri": "file:///tmp/vimtest", "name": "/tmp/vimtest"}]}}
===== stderr =====
2020/03/27 11:40:07 debug server listening on port 37009
===== received =====
Content-Length: 881

{"jsonrpc":"2.0","result":{"capabilities":{"textDocumentSync":{"openClose":true,"change":2,"save":{}},"completionProvider":{"triggerCharacters":["."]},"hoverProvider":true,"signatureHelpProvider":{"triggerCharacters":["(",","]},"definitionProvider":true,"typeDefinitionProvider":true,"implementationProvider":true,"referencesProvider":true,"documentHighlightProvider":true,"documentSymbolProvider":true,"codeActionProvider":true,"codeLensProvider":{},"documentLinkProvider":{},"workspaceSymbolProvider":true,"documentFormattingProvider":true,"documentOnTypeFormattingProvider":{"firstTriggerCharacter":""},"renameProvider":true,"foldingRangeProvider":true,"executeCommandProvider":{"commands":["tidy","upgrade.dependency","generate"]},"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":"workspace/didChangeWorkspaceFolders"}}},"serverInfo":{"name":""}},"id":1}
===== sent =====
Content-Length: 57

{"method": "initialized", "jsonrpc": "2.0", "params": {}}
===== sent =====
Content-Length: 368

{"method": "textDocument/didOpen", "jsonrpc": "2.0", "params": {"textDocument": {"uri": "file:///tmp/vimtest/test.go", "version": 1, "languageId": "go", "text": "package main\n\nimport (\n\t\"fmt\"\n\t\"github.com/minight/vimtest/pkg/bar\"\n)\n\nfunc main() {\n\tfmt.Println(\"vim-go\")\n\tbars := bar.GetBars()\n\tfor _, b := range bars {\n\t\t_ = b.Baz\n\t}\n}\n"}}}
===== received =====
Content-Length: 268

{"jsonrpc":"2.0","method":"client/registerCapability","params":{"registrations":[{"id":"workspace/didChangeConfiguration","method":"workspace/didChangeConfiguration"},{"id":"workspace/didChangeWorkspaceFolders","method":"workspace/didChangeWorkspaceFolders"}]},"id":1}
===== sent =====
Content-Length: 43

{"id": 1, "jsonrpc": "2.0", "result": null}
===== received =====
Content-Length: 199

{"jsonrpc":"2.0","method":"workspace/configuration","params":{"items":[{"scopeUri":"file:///tmp/vimtest","section":"gopls"},{"scopeUri":"file:///tmp/vimtest","section":"gopls-/tmp/vimtest"}]},"id":2}
===== sent =====
Content-Length: 143

{"id": 2, "jsonrpc": "2.0", "result": [{"buildFlags": [], "hoverKind": "NoDocumentation"}, {"buildFlags": [], "hoverKind": "NoDocumentation"}]}
===== received =====
Content-Length: 1061

{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2020/03/27 11:40:07 Build info\n----------\ngolang.org/x/tools/gopls master\n    golang.org/x/tools/gopls@v0.1.8-0.20200326210457-5d86d385bf88 h1:VHwe8L5z49UodPQ00s8OuYq5xk8LjagpydtFF7m+JCo=\n    github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=\n    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=\n    golang.org/x/mod@v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=\n    golang.org/x/sync@v0.0.0-20200317015054-43a5402ce75a h1:WXEvlFVvvGxCJLG6REjsT03iWnKLEWinaScsxF2Vm2o=\n    golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88 h1:F7fM2kxXfuWw820fa+MMCCLH6hmYe+jtLnZpwoiLK4Q=\n    golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=\n    honnef.co/go/tools@v0.0.1-2020.1.3 h1:sXmLre5bzIR6ypkjXCDI3jHPssRhc8KD/Ome589sc3U=\n    mvdan.cc/xurls/v2@v2.1.0 h1:KaMb5GLhlcSX+e+qhbRJODnUUBvlw01jt4yrjFIHAuA=\n\nGo info\n-------\ngo version go1.14 linux/amd64\n\n"}}
===== received =====
Content-Length: 1062

{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2020/03/27 11:40:08 go env for /tmp/vimtest\n(valid build configuration = true)\n(build flags: [-modfile=/tmp/go.vimtest.261704618.mod])\nGO111MODULE=\"\"\nGOARCH=\"amd64\"\nGOBIN=\"\"\nGOCACHE=\"/home/sean/.cache/go-build\"\nGOENV=\"/home/sean/.config/go/env\"\nGOEXE=\"\"\nGOFLAGS=\"\"\nGOHOSTARCH=\"amd64\"\nGOHOSTOS=\"linux\"\nGOINSECURE=\"\"\nGONOPROXY=\"\"\nGONOSUMDB=\"\"\nGOOS=\"linux\"\nGOPATH=\"/home/sean/.go\"\nGOPRIVATE=\"\"\nGOPROXY=\"https://proxy.golang.org,direct\"\nGOROOT=\"/usr/local/go\"\nGOSUMDB=\"sum.golang.org\"\nGOTMPDIR=\"\"\nGOTOOLDIR=\"/usr/local/go/pkg/tool/linux_amd64\"\nGCCGO=\"gccgo\"\nAR=\"ar\"\nCC=\"gcc\"\nCXX=\"g++\"\nCGO_ENABLED=\"1\"\nGOMOD=\"/tmp/vimtest/go.mod\"\nCGO_CFLAGS=\"-g -O2\"\nCGO_CPPFLAGS=\"\"\nCGO_CXXFLAGS=\"-g -O2\"\nCGO_FFLAGS=\"-g -O2\"\nCGO_LDFLAGS=\"-g -O2\"\nPKG_CONFIG=\"pkg-config\"\nGOGCCFLAGS=\"-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build705483024=/tmp/go-build -gno-record-gcc-switches\"\n"}}
===== received =====
Content-Length: 206

{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2020/03/27 11:40:08 go/packages.Load\n\tsnapshot=0\n\tdirectory=\"/tmp/vimtest\"\n\tquery=[\"./...\" \"builtin\"]\n\tpackages=5"}}
===== received =====
Content-Length: 673

{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///tmp/vimtest/pkg/bar/pb/bar.pb.go","diagnostics":[{"range":{"start":{"line":7,"character":3},"end":{"line":7,"character":39}},"severity":2,"source":"go mod tidy","message":"github.com/gogo/protobuf is not in your go.mod file."},{"range":{"start":{"line":8,"character":7},"end":{"line":8,"character":39}},"severity":2,"source":"go mod tidy","message":"github.com/gogo/protobuf is not in your go.mod file."},{"range":{"start":{"line":10,"character":32},"end":{"line":10,"character":64}},"severity":2,"source":"go mod tidy","message":"github.com/gogo/protobuf is not in your go.mod file."}]}}
===== sent =====
Content-Length: 372

{"method": "textDocument/didChange", "jsonrpc": "2.0", "params": {"contentChanges": [{"text": "package main\n\nimport (\n\t\"fmt\"\n\t\"github.com/minight/vimtest/pkg/bar\"\n)\n\nfunc main() {\n\tfmt.Println(\"vim-go\")\n\tbars := bar.GetBars()\n\tfor _, b := range bars {\n\t\t_ = b.Baz\n\t}\n}\n"}], "textDocument": {"uri": "file:///tmp/vimtest/test.go", "version": 2}}}
===== sent =====
Content-Length: 174

{"method": "textDocument/definition", "jsonrpc": "2.0", "id": 2, "params": {"textDocument": {"uri": "file:///tmp/vimtest/test.go"}, "position": {"character": 9, "line": 11}}}
===== sent =====
Content-Length: 372

{"method": "textDocument/didChange", "jsonrpc": "2.0", "params": {"contentChanges": [{"text": "package main\n\nimport (\n\t\"fmt\"\n\t\"github.com/minight/vimtest/pkg/bar\"\n)\n\nfunc main() {\n\tfmt.Println(\"vim-go\")\n\tbars := bar.GetBars()\n\tfor _, b := range bars {\n\t\t_ = b.Baz\n\t}\n}\n"}], "textDocument": {"uri": "file:///tmp/vimtest/test.go", "version": 3}}}
===== sent =====
Content-Length: 215

{"method": "textDocument/references", "jsonrpc": "2.0", "id": 3, "params": {"context": {"includeDeclaration": true}, "textDocument": {"uri": "file:///tmp/vimtest/test.go"}, "position": {"character": 9, "line": 11}}}
===== received =====
Content-Length: 162

{"jsonrpc":"2.0","result":[{"uri":"file:///tmp/vimtest/pkg/bar/pb/bar.pb.go","range":{"start":{"line":35,"character":1},"end":{"line":35,"character":4}}}],"id":2}
===== sent =====
Content-Length: 182

{"method": "textDocument/hover", "jsonrpc": "2.0", "id": 4, "params": {"textDocument": {"uri": "file:///tmp/vimtest/pkg/bar/pb/bar.pb.go"}, "position": {"character": 1, "line": 35}}}
===== received =====
Content-Length: 121

{"jsonrpc":"2.0","error":{"code":-32603,"message":"method \"textDocument/references\" did not reply","data":null},"id":3}
===== stderr =====
panic: runtime error: invalid memory address or nil pointer dereference
===== stderr =====
[signal SIGSEGV: segmentation violation code=0x1 addr=0x60 pc=0x7d4518]
===== stderr =====
===== stderr =====
goroutine 2309 [running]:
===== stderr =====
golang.org/x/tools/internal/lsp/source.FindFileInPackage(0x0, 0x0, 0xc003d68cf0, 0x28, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/source/util.go:715 +0x108
===== stderr =====
golang.org/x/tools/internal/lsp/source.findMapperInPackage(0xe49ce0, 0xc0000ca000, 0x0, 0x0, 0xc003d68cf0, 0x28, 0x24, 0x2, 0xc003860a80)
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/source/util.go:687 +0x15e
===== stderr =====
golang.org/x/tools/internal/lsp/source.posToMappedRange(0xe49ce0, 0xc0000ca000, 0x0, 0x0, 0xe8016, 0xe8019, 0x0, 0x0, 0x0, 0x0, ...)
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/source/util.go:205 +0x15b
===== stderr =====
golang.org/x/tools/internal/lsp/source.nameToMappedRange(...)
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/source/util.go:200
===== stderr =====
golang.org/x/tools/internal/lsp/source.objToMappedRange(0xe49ce0, 0xc0000ca000, 0x0, 0x0, 0xe4a280, 0xc0006a3d10, 0x0, 0x0, 0x0, 0x0, ...)
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/source/util.go:196 +0x11a
===== stderr =====
golang.org/x/tools/internal/lsp/source.References(0xe382e0, 0xc00354cf30, 0xe49c40, 0xc0000f2150, 0xe36b60, 0xc003f00360, 0x4026000000000000, 0x4022000000000000, 0xc0003ebb01, 0x0, ...)
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/source/references.go:50 +0xe3b
===== stderr =====
golang.org/x/tools/internal/lsp.(*Server).references(0xc0001d9600, 0xe382e0, 0xc0013055c0, 0xc002ef3360, 0xc002ef3360, 0x0, 0x0, 0x0, 0xc001637760)
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/references.go:19 +0xe7
===== stderr =====
golang.org/x/tools/internal/lsp.(*Server).References(0xc0001d9600, 0xe382e0, 0xc0013055c0, 0xc002ef3360, 0xc002ef3360, 0x0, 0x0, 0x0, 0x0)
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/server_gen.go:144 +0x4d
===== stderr =====
golang.org/x/tools/internal/lsp/protocol.serverHandler.Deliver(0xe52160, 0xc0001d9600, 0xe382e0, 0xc0013055c0, 0xc0037d43c0, 0x1375800, 0xc000730000)
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/protocol/tsserver.go:377 +0x251f
===== stderr =====
golang.org/x/tools/internal/jsonrpc2.(*Conn).Run.func1(0xc00296ac00, 0xc0037d43c0, 0xc000273590, 0xe382e0, 0xc0013055c0, 0x0, 0x0, 0xc003540270)
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/jsonrpc2/jsonrpc2.go:371 +0x160
===== stderr =====
created by golang.org/x/tools/internal/jsonrpc2.(*Conn).Run
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/jsonrpc2/jsonrpc2.go:355 +0x850
===== sent =====
Content-Length: 372

{"method": "textDocument/didChange", "jsonrpc": "2.0", "params": {"contentChanges": [{"text": "package main\n\nimport (\n\t\"fmt\"\n\t\"github.com/minight/vimtest/pkg/bar\"\n)\n\nfunc main() {\n\tfmt.Println(\"vim-go\")\n\tbars := bar.GetBars()\n\tfor _, b := range bars {\n\t\t_ = b.Baz\n\t}\n}\n"}], "textDocument": {"uri": "file:///tmp/vimtest/test.go", "version": 4}}}
===== sent =====
Content-Length: 174

{"method": "textDocument/definition", "jsonrpc": "2.0", "id": 5, "params": {"textDocument": {"uri": "file:///tmp/vimtest/test.go"}, "position": {"character": 7, "line": 11}}}
===== sent =====
Content-Length: 372

{"method": "textDocument/didChange", "jsonrpc": "2.0", "params": {"contentChanges": [{"text": "package main\n\nimport (\n\t\"fmt\"\n\t\"github.com/minight/vimtest/pkg/bar\"\n)\n\nfunc main() {\n\tfmt.Println(\"vim-go\")\n\tbars := bar.GetBars()\n\tfor _, b := range bars {\n\t\t_ = b.Baz\n\t}\n}\n"}], "textDocument": {"uri": "file:///tmp/vimtest/test.go", "version": 5}}}

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Mar 27, 2020

Does the test.go file exist on disk when you open it?

My guess is that this might be an issue with vim-go, which is causing gopls to get into an invalid state. We should still never call that function with an invalid package, so I will make sure to get that fix in. One thing I noticed from your log is that vim-go sends 4 identical textDocument/didChange requests (the only difference is the version numbers), which might be something that @bhcleek wants to take a look at. You can confirm that this isn't a gopls issue by running gopls -rpc.trace -v query definition ./test.go:13:15.

@minight
Copy link
Author

@minight minight commented Mar 27, 2020

Does the test.go file exist on disk when you open it?

the entire directory tree exists on disk.

My guess is that this might be an issue with vim-go, which is causing gopls to get into an invalid state

I've filed fatih/vim-go#2787 with the full config.vim used to repro and a gif.

You can confirm that this isn't a gopls issue by running gopls -rpc.trace -v query definition ./test.go:13:15.

I can confirm gopls doesn't crash when running

$ gopls -rpc.trace -v query definition ./test.go:12:16
2020/03/27 12:46:52 Info:2020/03/27 12:46:52 Build info
----------
golang.org/x/tools/gopls master
    golang.org/x/tools/gopls@v0.1.8-0.20200326210457-5d86d385bf88 h1:VHwe8L5z49UodPQ00s8OuYq5xk8LjagpydtFF7m+JCo=
    github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/mod@v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=
    golang.org/x/sync@v0.0.0-20200317015054-43a5402ce75a h1:WXEvlFVvvGxCJLG6REjsT03iWnKLEWinaScsxF2Vm2o=
    golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88 h1:F7fM2kxXfuWw820fa+MMCCLH6hmYe+jtLnZpwoiLK4Q=
    golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
    honnef.co/go/tools@v0.0.1-2020.1.3 h1:sXmLre5bzIR6ypkjXCDI3jHPssRhc8KD/Ome589sc3U=
    mvdan.cc/xurls/v2@v2.1.0 h1:KaMb5GLhlcSX+e+qhbRJODnUUBvlw01jt4yrjFIHAuA=

Go info
-------
go version go1.14 linux/amd64

2020/03/27 12:46:52 Info:2020/03/27 12:46:52 go env for /tmp/vimtest
(valid build configuration = true)
(build flags: [-modfile=/tmp/go.vimtest.345813191.mod])
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/sean/.cache/go-build"
GOENV="/home/sean/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/sean/.go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/tmp/vimtest/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-build533600123=/tmp/go-build -gno-record-gcc-switches"
2020/03/27 12:46:53 Info:2020/03/27 12:46:53 go/packages.Load
        snapshot=0
        directory="/tmp/vimtest"
        query=["./..." "builtin"]
        packages=4
/tmp/vimtest/pkg/bar/pb/bar.pb.go:36:2-5: defined here as field Baz int64% 

oh for reference, I'm also using neovim instead of vim

NVIM v0.3.8
Build type: Release
LuaJIT 2.1.0-beta3

More reliably, I am able to trigger the bug upon opening vim with

vim -u config.vim "+12 normal $" test.go
<press b to navigate to the beginning of the word 'Baz'>

Peek 2020-03-27 13-10

===== sent =====
Content-Length: 456

{"method": "initialize", "jsonrpc": "2.0", "id": 1, "params": {"rootUri": "file:///tmp/vimtest", "capabilities": {"workspace": {"workspaceFolders": true, "configuration": true, "didChangeConfiguration": {"dynamicRegistration": true}}, "textDocument": {"completion": {"completionItem": {"snippetSupport": false}}, "hover": {"contentFormat": ["plaintext"]}}}, "processId": 24504, "workspaceFolders": [{"uri": "file:///tmp/vimtest", "name": "/tmp/vimtest"}]}}
===== stderr =====
2020/03/27 13:01:21 debug server listening on port 35559
===== received =====
Content-Length: 881

{"jsonrpc":"2.0","result":{"capabilities":{"textDocumentSync":{"openClose":true,"change":2,"save":{}},"completionProvider":{"triggerCharacters":["."]},"hoverProvider":true,"signatureHelpProvider":{"triggerCharacters":["(",","]},"definitionProvider":true,"typeDefinitionProvider":true,"implementationProvider":true,"referencesProvider":true,"documentHighlightProvider":true,"documentSymbolProvider":true,"codeActionProvider":true,"codeLensProvider":{},"documentLinkProvider":{},"workspaceSymbolProvider":true,"documentFormattingProvider":true,"documentOnTypeFormattingProvider":{"firstTriggerCharacter":""},"renameProvider":true,"foldingRangeProvider":true,"executeCommandProvider":{"commands":["tidy","upgrade.dependency","generate"]},"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":"workspace/didChangeWorkspaceFolders"}}},"serverInfo":{"name":""}},"id":1}
===== sent =====
Content-Length: 57

{"method": "initialized", "jsonrpc": "2.0", "params": {}}
===== sent =====
Content-Length: 368

{"method": "textDocument/didOpen", "jsonrpc": "2.0", "params": {"textDocument": {"uri": "file:///tmp/vimtest/test.go", "version": 1, "languageId": "go", "text": "package main\n\nimport (\n\t\"fmt\"\n\t\"github.com/minight/vimtest/pkg/bar\"\n)\n\nfunc main() {\n\tfmt.Println(\"vim-go\")\n\tbars := bar.GetBars()\n\tfor _, b := range bars {\n\t\t_ = b.Baz\n\t}\n}\n"}}}
===== received =====
Content-Length: 268

{"jsonrpc":"2.0","method":"client/registerCapability","params":{"registrations":[{"id":"workspace/didChangeConfiguration","method":"workspace/didChangeConfiguration"},{"id":"workspace/didChangeWorkspaceFolders","method":"workspace/didChangeWorkspaceFolders"}]},"id":1}
===== sent =====
Content-Length: 43

{"id": 1, "jsonrpc": "2.0", "result": null}
===== received =====
Content-Length: 199

{"jsonrpc":"2.0","method":"workspace/configuration","params":{"items":[{"scopeUri":"file:///tmp/vimtest","section":"gopls"},{"scopeUri":"file:///tmp/vimtest","section":"gopls-/tmp/vimtest"}]},"id":2}
===== sent =====
Content-Length: 143

{"id": 2, "jsonrpc": "2.0", "result": [{"buildFlags": [], "hoverKind": "NoDocumentation"}, {"buildFlags": [], "hoverKind": "NoDocumentation"}]}
===== received =====
Content-Length: 1061

{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2020/03/27 13:01:21 Build info\n----------\ngolang.org/x/tools/gopls master\n    golang.org/x/tools/gopls@v0.1.8-0.20200326210457-5d86d385bf88 h1:VHwe8L5z49UodPQ00s8OuYq5xk8LjagpydtFF7m+JCo=\n    github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=\n    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=\n    golang.org/x/mod@v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=\n    golang.org/x/sync@v0.0.0-20200317015054-43a5402ce75a h1:WXEvlFVvvGxCJLG6REjsT03iWnKLEWinaScsxF2Vm2o=\n    golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88 h1:F7fM2kxXfuWw820fa+MMCCLH6hmYe+jtLnZpwoiLK4Q=\n    golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=\n    honnef.co/go/tools@v0.0.1-2020.1.3 h1:sXmLre5bzIR6ypkjXCDI3jHPssRhc8KD/Ome589sc3U=\n    mvdan.cc/xurls/v2@v2.1.0 h1:KaMb5GLhlcSX+e+qhbRJODnUUBvlw01jt4yrjFIHAuA=\n\nGo info\n-------\ngo version go1.14 linux/amd64\n\n"}}
===== received =====
Content-Length: 1062

{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2020/03/27 13:01:21 go env for /tmp/vimtest\n(valid build configuration = true)\n(build flags: [-modfile=/tmp/go.vimtest.647729188.mod])\nGO111MODULE=\"\"\nGOARCH=\"amd64\"\nGOBIN=\"\"\nGOCACHE=\"/home/sean/.cache/go-build\"\nGOENV=\"/home/sean/.config/go/env\"\nGOEXE=\"\"\nGOFLAGS=\"\"\nGOHOSTARCH=\"amd64\"\nGOHOSTOS=\"linux\"\nGOINSECURE=\"\"\nGONOPROXY=\"\"\nGONOSUMDB=\"\"\nGOOS=\"linux\"\nGOPATH=\"/home/sean/.go\"\nGOPRIVATE=\"\"\nGOPROXY=\"https://proxy.golang.org,direct\"\nGOROOT=\"/usr/local/go\"\nGOSUMDB=\"sum.golang.org\"\nGOTMPDIR=\"\"\nGOTOOLDIR=\"/usr/local/go/pkg/tool/linux_amd64\"\nGCCGO=\"gccgo\"\nAR=\"ar\"\nCC=\"gcc\"\nCXX=\"g++\"\nCGO_ENABLED=\"1\"\nGOMOD=\"/tmp/vimtest/go.mod\"\nCGO_CFLAGS=\"-g -O2\"\nCGO_CPPFLAGS=\"\"\nCGO_CXXFLAGS=\"-g -O2\"\nCGO_FFLAGS=\"-g -O2\"\nCGO_LDFLAGS=\"-g -O2\"\nPKG_CONFIG=\"pkg-config\"\nGOGCCFLAGS=\"-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build569866965=/tmp/go-build -gno-record-gcc-switches\"\n"}}
===== received =====
Content-Length: 206

{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2020/03/27 13:01:21 go/packages.Load\n\tsnapshot=0\n\tdirectory=\"/tmp/vimtest\"\n\tquery=[\"./...\" \"builtin\"]\n\tpackages=4"}}
===== received =====
Content-Length: 673

{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///tmp/vimtest/pkg/bar/pb/bar.pb.go","diagnostics":[{"range":{"start":{"line":7,"character":3},"end":{"line":7,"character":39}},"severity":2,"source":"go mod tidy","message":"github.com/gogo/protobuf is not in your go.mod file."},{"range":{"start":{"line":8,"character":7},"end":{"line":8,"character":39}},"severity":2,"source":"go mod tidy","message":"github.com/gogo/protobuf is not in your go.mod file."},{"range":{"start":{"line":10,"character":32},"end":{"line":10,"character":64}},"severity":2,"source":"go mod tidy","message":"github.com/gogo/protobuf is not in your go.mod file."}]}}
===== sent =====
Content-Length: 372

{"method": "textDocument/didChange", "jsonrpc": "2.0", "params": {"contentChanges": [{"text": "package main\n\nimport (\n\t\"fmt\"\n\t\"github.com/minight/vimtest/pkg/bar\"\n)\n\nfunc main() {\n\tfmt.Println(\"vim-go\")\n\tbars := bar.GetBars()\n\tfor _, b := range bars {\n\t\t_ = b.Baz\n\t}\n}\n"}], "textDocument": {"uri": "file:///tmp/vimtest/test.go", "version": 2}}}
===== sent =====
Content-Length: 174

{"method": "textDocument/definition", "jsonrpc": "2.0", "id": 2, "params": {"textDocument": {"uri": "file:///tmp/vimtest/test.go"}, "position": {"character": 8, "line": 11}}}
===== sent =====
Content-Length: 372

{"method": "textDocument/didChange", "jsonrpc": "2.0", "params": {"contentChanges": [{"text": "package main\n\nimport (\n\t\"fmt\"\n\t\"github.com/minight/vimtest/pkg/bar\"\n)\n\nfunc main() {\n\tfmt.Println(\"vim-go\")\n\tbars := bar.GetBars()\n\tfor _, b := range bars {\n\t\t_ = b.Baz\n\t}\n}\n"}], "textDocument": {"uri": "file:///tmp/vimtest/test.go", "version": 3}}}
===== sent =====
Content-Length: 215

{"method": "textDocument/references", "jsonrpc": "2.0", "id": 3, "params": {"context": {"includeDeclaration": true}, "textDocument": {"uri": "file:///tmp/vimtest/test.go"}, "position": {"character": 8, "line": 11}}}
===== received =====
Content-Length: 162

{"jsonrpc":"2.0","result":[{"uri":"file:///tmp/vimtest/pkg/bar/pb/bar.pb.go","range":{"start":{"line":35,"character":1},"end":{"line":35,"character":4}}}],"id":2}
===== sent =====
Content-Length: 182

{"method": "textDocument/hover", "jsonrpc": "2.0", "id": 4, "params": {"textDocument": {"uri": "file:///tmp/vimtest/pkg/bar/pb/bar.pb.go"}, "position": {"character": 1, "line": 35}}}
===== received =====
Content-Length: 121

{"jsonrpc":"2.0","error":{"code":-32603,"message":"method \"textDocument/references\" did not reply","data":null},"id":3}
===== stderr =====
panic: runtime error: invalid memory address or nil pointer dereference
===== stderr =====
[signal SIGSEGV: segmentation violation code=0x1 addr=0x60 pc=0x7d4518]
===== stderr =====
===== stderr =====
goroutine 2339 [running]:
===== stderr =====
golang.org/x/tools/internal/lsp/source.FindFileInPackage(0x0, 0x0, 0xc003b33380, 0x28, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/source/util.go:715 +0x108
===== stderr =====
golang.org/x/tools/internal/lsp/source.findMapperInPackage(0xe49ce0, 0xc000394000, 0x0, 0x0, 0xc003b33380, 0x28, 0x24, 0x2, 0xc003939320)
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/source/util.go:687 +0x15e
===== stderr =====
golang.org/x/tools/internal/lsp/source.posToMappedRange(0xe49ce0, 0xc000394000, 0x0, 0x0, 0x25de1d, 0x25de20, 0x0, 0x0, 0x0, 0x0, ...)
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/source/util.go:205 +0x15b
===== stderr =====
golang.org/x/tools/internal/lsp/source.nameToMappedRange(...)
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/source/util.go:200
===== stderr =====
golang.org/x/tools/internal/lsp/source.objToMappedRange(0xe49ce0, 0xc000394000, 0x0, 0x0, 0xe4a280, 0xc002f51e00, 0x0, 0x0, 0x0, 0x0, ...)
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/source/util.go:196 +0x11a
===== stderr =====
golang.org/x/tools/internal/lsp/source.References(0xe382e0, 0xc0037f4960, 0xe49c40, 0xc0002a0000, 0xe36b60, 0xc002e1d380, 0x4026000000000000, 0x4020000000000000, 0xc0006a7b01, 0x0, ...)
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/source/references.go:50 +0xe3b
===== stderr =====
golang.org/x/tools/internal/lsp.(*Server).references(0xc000319f80, 0xe382e0, 0xc003917680, 0xc0036d6b40, 0xc0036d6b40, 0x0, 0x0, 0x0, 0xc0022718c0)
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/references.go:19 +0xe7
===== stderr =====
golang.org/x/tools/internal/lsp.(*Server).References(0xc000319f80, 0xe382e0, 0xc003917680, 0xc0036d6b40, 0xc0036d6b40, 0x0, 0x0, 0x0, 0x0)
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/server_gen.go:144 +0x4d
===== stderr =====
golang.org/x/tools/internal/lsp/protocol.serverHandler.Deliver(0xe52160, 0xc000319f80, 0xe382e0, 0xc003917680, 0xc003579d40, 0xc000ad6f00, 0x400000)
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/protocol/tsserver.go:377 +0x251f
===== stderr =====
golang.org/x/tools/internal/jsonrpc2.(*Conn).Run.func1(0xc00045dd40, 0xc003579d40, 0xc000322aa0, 0xe382e0, 0xc003917680, 0x0, 0x0, 0xc002e22ed0)
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/jsonrpc2/jsonrpc2.go:371 +0x160
===== stderr =====
created by golang.org/x/tools/internal/jsonrpc2.(*Conn).Run
===== stderr =====
	/home/sean/.go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/jsonrpc2/jsonrpc2.go:355 +0x850
@gopherbot
Copy link

@gopherbot gopherbot commented Mar 27, 2020

Change https://golang.org/cl/225777 mentions this issue: internal/lsp: refactor references/rename/implementations

gopherbot pushed a commit to golang/tools that referenced this issue Mar 27, 2020
As part of investigating golang/go#38100, I noticed a few things that I
wanted to clean up. Mostly, for renames, we were calling
qualifiedObjAtProtocolPos twice, so I factored out a shared helper
function. I also added an error return for builtins so that callers
don't have to check.

Change-Id: I28c75c801cbec1611736af931cfa72befd219201
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225777
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rohan Challa <rohan@golang.org>
@bhcleek
Copy link
Contributor

@bhcleek bhcleek commented Mar 28, 2020

One thing I noticed from your log is that vim-go sends 4 identical textDocument/didChange requests (the only difference is the version numbers), which might be something that @bhcleek wants to take a look at.

Vim-go sends textDocument/didChange before other requests to make sure that gopls has the current version. There are a number of events that can be hooked into in Vim to know when files changes, but it's difficult to cover all the cases well.

You can confirm that this isn't a gopls issue by running gopls -rpc.trace -v query definition ./test.go:13:15

I can duplicate the issue, but I don't see how this is a vim-go issue. Running gopls references test.go:12:12 causes gopls to panic:

❯❯❯ gopls -rpc.trace -v references ./test.go:12:12
2020/03/28 15:35:20 Info:2020/03/28 15:35:20 Build info
----------
golang.org/x/tools/gopls v0.3.4
    golang.org/x/tools/gopls@v0.3.4 h1:4GC7q/pXQ/tsxHBGVdsMdlB4gCxVC06m/7rIXg1Px4E=
    github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
    github.com/sergi/go-diff@v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
    golang.org/x/mod@v0.1.1-0.20191105210325-c90efee705ee h1:WG0RUwxtNT4qqaXX3DPA8zHFNm/D9xaBpxzHt1WcA/E=
    golang.org/x/sync@v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
    golang.org/x/tools@v0.0.0-20200316194252-fafb6e2e8a4a h1:hKrQy/q8/Xivoqgw6nGiz1jqpn1WGBLDcWLZwW0983E=
    golang.org/x/xerrors@v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA=
    honnef.co/go/tools@v0.0.1-2020.1.3 h1:sXmLre5bzIR6ypkjXCDI3jHPssRhc8KD/Ome589sc3U=
    mvdan.cc/xurls/v2@v2.1.0 h1:KaMb5GLhlcSX+e+qhbRJODnUUBvlw01jt4yrjFIHAuA=

Go info
-------
go version go1.14 darwin/amd64

GO111MODULE=""
GOARCH="amd64"
GOBIN="/Users/bhcleek/go/bin"
GOCACHE="/Users/bhcleek/Library/Caches/go-build"
GOENV="/Users/bhcleek/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY="*.internal.digitalocean.com,github.com/digitalocean"
GONOSUMDB="*.internal.digitalocean.com,github.com/digitalocean"
GOOS="darwin"
GOPATH="/Users/bhcleek/go"
GOPRIVATE="*.internal.digitalocean.com,github.com/digitalocean"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/bhcleek/src/vim-go/issues/2787/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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/f9/d6g779t53gq_20w0zm2f_1zm0000gn/T/go-build098065432=/tmp/go-build -gno-record-gcc-switches -fno-common"
2020/03/28 15:35:20 Info:2020/03/28 15:35:20 go/packages.Load
        snapshot = 0
        query = [./... builtin]
        packages = 4
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x60 pc=0x13be46b]

goroutine 1 [running]:
golang.org/x/tools/internal/lsp/source.References(0x1a12540, 0xc0002ff7d0, 0x1a24740, 0xc000208000, 0x1a10c00, 0xc000308300, 0x4026000000000000, 0x4026000000000000, 0xc00003bd00, 0x0, ...)
        /Users/bhcleek/go/pkg/mod/golang.org/x/tools@v0.0.0-20200316194252-fafb6e2e8a4a/internal/lsp/source/references.go:71 +0xb4b
golang.org/x/tools/internal/lsp.(*Server).references(0xc00034c980, 0x1a124c0, 0xc0000a2000, 0xc0000af770, 0x100ea48, 0x50, 0x1835120, 0x1, 0xc0000af770)
        /Users/bhcleek/go/pkg/mod/golang.org/x/tools@v0.0.0-20200316194252-fafb6e2e8a4a/internal/lsp/references.go:19 +0xe7
golang.org/x/tools/internal/lsp.(*Server).References(0xc00034c980, 0x1a124c0, 0xc0000a2000, 0xc0000af770, 0xc, 0xffffffffffffffff, 0xc, 0xc, 0xffffffffffffffff)
        /Users/bhcleek/go/pkg/mod/golang.org/x/tools@v0.0.0-20200316194252-fafb6e2e8a4a/internal/lsp/server_gen.go:148 +0x4d
golang.org/x/tools/internal/lsp/cmd.(*references).Run(0xc000305980, 0x1a124c0, 0xc0000a2000, 0xc0000ae040, 0x1, 0x1, 0x0, 0x0)
        /Users/bhcleek/go/pkg/mod/golang.org/x/tools@v0.0.0-20200316194252-fafb6e2e8a4a/internal/lsp/cmd/references.go:70 +0x373
golang.org/x/tools/internal/tool.Run(0x1a124c0, 0xc0000a2000, 0x1a16600, 0xc000305980, 0xc0000ae040, 0x1, 0x1, 0x0, 0x0)
        /Users/bhcleek/go/pkg/mod/golang.org/x/tools@v0.0.0-20200316194252-fafb6e2e8a4a/internal/tool/tool.go:152 +0x29d
golang.org/x/tools/internal/lsp/cmd.(*Application).Run(0xc000356120, 0x1a124c0, 0xc0000a2000, 0xc0000ae040, 0x2, 0x2, 0x0, 0x0)
        /Users/bhcleek/go/pkg/mod/golang.org/x/tools@v0.0.0-20200316194252-fafb6e2e8a4a/internal/lsp/cmd/cmd.go:142 +0x2a4
golang.org/x/tools/internal/tool.Run(0x1a124c0, 0xc0000a2000, 0x1a162c0, 0xc000356120, 0xc0000ae010, 0x4, 0x4, 0x0, 0x0)
        /Users/bhcleek/go/pkg/mod/golang.org/x/tools@v0.0.0-20200316194252-fafb6e2e8a4a/internal/tool/tool.go:152 +0x29d
golang.org/x/tools/internal/tool.Main(0x1a124c0, 0xc0000a2000, 0x1a162c0, 0xc000356120, 0xc0000ae010, 0x4, 0x4)
        /Users/bhcleek/go/pkg/mod/golang.org/x/tools@v0.0.0-20200316194252-fafb6e2e8a4a/internal/tool/tool.go:91 +0x12f
main.main()
        /Users/bhcleek/go/pkg/mod/golang.org/x/tools/gopls@v0.3.4/main.go:25 +0xdb
@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Mar 30, 2020

gopls/v0.3.4 did panic, but @minight seems to be using gopls at master, which included a fix for a related issue.

@minight: Does the issue still exist with gopls at master?

@minight
Copy link
Author

@minight minight commented Mar 31, 2020

At current master, gopls does not panic

sean at pop-os in ~/vimtest 
$ cat test.go
package main

import (
        "fmt"
        "github.com/minight/vimtest/pkg/bar"
)

func main() {
        fmt.Println("vim-go")
        bars := bar.GetBars()
        for _, b := range bars {
                _ = b.Baz
        }
}

sean at pop-os in ~/vimtest
$ md5sum test.go
1b6b8c7b050c847d540c47f2077abb29  test.go

sean at pop-os in ~/vimtest
$ gopls version
golang.org/x/tools/gopls master
    golang.org/x/tools/gopls@v0.1.8-0.20200331025713-a30bf2db82d4 h1:5Ve4Z+UFE8eEmEgLnk6KGM7oelFrC+NOCWtAAZ3G+7I=

sean at pop-os in ~/vimtest
$ gopls -rpc.trace -v references ./test.go:12:12

2020/03/31 16:16:19 Info:2020/03/31 16:16:19 Build info
----------
golang.org/x/tools/gopls master
    golang.org/x/tools/gopls@v0.1.8-0.20200331025713-a30bf2db82d4 h1:5Ve4Z+UFE8eEmEgLnk6KGM7oelFrC+NOCWtAAZ3G+7I=
    github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/mod@v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=
    golang.org/x/sync@v0.0.0-20200317015054-43a5402ce75a h1:WXEvlFVvvGxCJLG6REjsT03iWnKLEWinaScsxF2Vm2o=
    golang.org/x/tools@v0.0.0-20200331025713-a30bf2db82d4 h1:kDtqNkeBrZb8B+atrj50B5XLHpzXXqcCdZPP/ApQ5NY=
    golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
    honnef.co/go/tools@v0.0.1-2020.1.3 h1:sXmLre5bzIR6ypkjXCDI3jHPssRhc8KD/Ome589sc3U=
    mvdan.cc/xurls/v2@v2.1.0 h1:KaMb5GLhlcSX+e+qhbRJODnUUBvlw01jt4yrjFIHAuA=

Go info
-------
go version go1.14 linux/amd64


        message="Build info\n----------\ngolang.org/x/tools/gopls master\n    golang.org/x/tools/gopls@v0.1.8-0.20200331025713-a30bf2db82d4 h1:5Ve4Z+UFE8eEmEgLnk6KGM7oelFrC+NOCWtAAZ3G+7I=\n    github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=\n    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=\n    golang.org/x/mod@v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=\n    golang.org/x/sync@v0.0.0-20200317015054-43a5402ce75a h1:WXEvlFVvvGxCJLG6REjsT03iWnKLEWinaScsxF2Vm2o=\n    golang.org/x/tools@v0.0.0-20200331025713-a30bf2db82d4 h1:kDtqNkeBrZb8B+atrj50B5XLHpzXXqcCdZPP/ApQ5NY=\n    golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=\n    honnef.co/go/tools@v0.0.1-2020.1.3 h1:sXmLre5bzIR6ypkjXCDI3jHPssRhc8KD/Ome589sc3U=\n    mvdan.cc/xurls/v2@v2.1.0 h1:KaMb5GLhlcSX+e+qhbRJODnUUBvlw01jt4yrjFIHAuA=\n\nGo info\n-------\ngo version go1.14 linux/amd64\n\n"
2020/03/31 16:16:19 Info:2020/03/31 16:16:19 go env for /home/sean/vimtest
(valid build configuration = true)
(build flags: [-modfile=/tmp/go.vimtest.766439690.mod])
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/sean/.cache/go-build"
GOENV="/home/sean/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY="github.com/assetnote"
GONOSUMDB="github.com/assetnote"
GOOS="linux"
GOPATH="/home/sean/.go"
GOPRIVATE="github.com/assetnote"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/sean/vimtest/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-build869507472=/tmp/go-build -gno-record-gcc-switches"

        message="go env for /home/sean/vimtest\n(valid build configuration = true)\n(build flags: [-modfile=/tmp/go.vimtest.766439690.mod])\nGO111MODULE=\"\"\nGOARCH=\"amd64\"\nGOBIN=\"\"\nGOCACHE=\"/home/sean/.cache/go-build\"\nGOENV=\"/home/sean/.config/go/env\"\nGOEXE=\"\"\nGOFLAGS=\"\"\nGOHOSTARCH=\"amd64\"\nGOHOSTOS=\"linux\"\nGOINSECURE=\"\"\nGONOPROXY=\"github.com/assetnote\"\nGONOSUMDB=\"github.com/assetnote\"\nGOOS=\"linux\"\nGOPATH=\"/home/sean/.go\"\nGOPRIVATE=\"github.com/assetnote\"\nGOPROXY=\"https://proxy.golang.org,direct\"\nGOROOT=\"/usr/local/go\"\nGOSUMDB=\"sum.golang.org\"\nGOTMPDIR=\"\"\nGOTOOLDIR=\"/usr/local/go/pkg/tool/linux_amd64\"\nGCCGO=\"gccgo\"\nAR=\"ar\"\nCC=\"gcc\"\nCXX=\"g++\"\nCGO_ENABLED=\"1\"\nGOMOD=\"/home/sean/vimtest/go.mod\"\nCGO_CFLAGS=\"-g -O2\"\nCGO_CPPFLAGS=\"\"\nCGO_CXXFLAGS=\"-g -O2\"\nCGO_FFLAGS=\"-g -O2\"\nCGO_LDFLAGS=\"-g -O2\"\nPKG_CONFIG=\"pkg-config\"\nGOGCCFLAGS=\"-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build869507472=/tmp/go-build -gno-record-gcc-switches\"\n"
2020/03/31 16:16:23 Info:2020/03/31 16:16:23 go/packages.Load
        message="go/packages.Load"
        snapshot=0
        directory="/home/sean/vimtest"
        query=["./..." "builtin"]
        packages=4
2020/03/31 16:16:23 : no package for obj field Baz int64: package pb ("github.com/minight/vimtest/pkg/bar/pb")
        message=""
        error="no package for obj field Baz int64: package pb (\"github.com/minight/vimtest/pkg/bar/pb\")"
gopls: no object found

@gopherbot
Copy link

@gopherbot gopherbot commented Apr 2, 2020

Change https://golang.org/cl/227030 mentions this issue: internal/lsp: fix references for transitive dependencies

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Apr 2, 2020

Thanks for bearing with me! I've figured out the cause of this issue, and it should be fixed by the CL linked above.

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Apr 2, 2020

Not sure why gopherbot didn't close this.

@stamblerre stamblerre closed this Apr 2, 2020
myitcv pushed a commit to myitcvforks/tools that referenced this issue Apr 6, 2020
We need to search all transitive dependencies of a package, not just its
immediate imports.

Fixes golang/go#38100

Change-Id: I15b4dbe226ba851691ca0c95460c3648ede32f04
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227030
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rohan Challa <rohan@golang.org>
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.