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

vim-go causing go-pls to enter panic state on References #2787

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

vim-go causing go-pls to enter panic state on References #2787

minight opened this issue Mar 27, 2020 · 3 comments

Comments

@minight
Copy link

minight commented Mar 27, 2020

What did you do? (required: The issue will be closed when not provided)

Related to golang/go#38100. This issue has been created incase vim-go is related.

With the following example project: https://play.golang.org/p/SrULcmi-Xbb in the following directory structure

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

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

(config.vim is provided separately below)

Peek 2020-03-27 13-10

What did you expect to happen?

Baz to be highlighted, and the type for Baz to appear in the statusline

What happened instead?

vim-go causes gopls to panic.

===== 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

Configuration (MUST fill this out):

vim-go version:

vimrc you used to reproduce:

vimrc
" vim-plug autoconfig if not already installed
if empty(glob('~/.config/nvim/autoload/plug.vim'))
  silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  autocmd VimEnter * PlugInstall | nested source $MYVIMRC
endif

call plug#begin('~/.config/nvim/bundle')
Plug 'preservim/nerdtree'
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
call plug#end()

" vim-go {
let g:go_def_mode='gopls'
let g:go_info_mode='gopls'
let g:go_highlight_build_constraints = 1
let g:go_highlight_extra_types = 1
let g:go_highlight_fields = 1
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_operators = 1
let g:go_highlight_structs = 1
let g:go_highlight_types = 1
let g:go_auto_sameids = 1
let g:go_auto_type_info = 1

let g:go_debug=["lsp"]

" }

let mapleader = "<Space>"
" nerdtree {
nnoremap f :NERDTreeFind
nnoremap n :NERDTreeToggle
" }

" Mappings {
set mouse=a
if !has('nvim') && exists('$TMUX') " Support resizing in tmux
set ttymouse=xterm2
endif
" }

Vim version (first three lines from :version):

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

Go version (go version):

go version go1.14 linux/amd64

Go environment

go env Output:
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-build156561905=/tmp/go-build -gno-record-gcc-switches"

gopls version

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

vim-go configuration:

vim-go configuration
g:go_auto_type_info = 1
g:go_highlight_methods = 1
g:go_highlight_fields = 1
g:go_auto_sameids = 1
g:go_highlight_structs = 1
g:go_loaded_gosnippets = 1
g:go_highlight_extra_types = 1
g:go_loaded_install = 1
g:go_highlight_functions = 1
g:go_highlight_operators = 1
g:go_highlight_build_constraints = 1
g:go_def_mode = 'gopls'
g:go_debug = ['lsp']
g:go_jump_to_error = 1
g:go_info_mode = 'gopls'
g:go_highlight_types = 1

filetype detection configuration:

filetype detection
filetype detection:ON  plugin:ON  indent:ON
@bhcleek
Copy link
Collaborator

bhcleek commented Mar 27, 2020

Thank you for a clear reproduction case! I'll take a close look over the weekend and see if vim-go needs to be adjusted.

@bhcleek
Copy link
Collaborator

bhcleek commented Mar 28, 2020

I'm pretty sure this is a gopls issue and not something that vim-go can resolve. Details are in golang/go#38100 (comment)

@bhcleek
Copy link
Collaborator

bhcleek commented Apr 5, 2020

Closing because this has been resolved on gopls master.

@bhcleek bhcleek closed this as completed Apr 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants