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

go_auto_sameids causes gopls panic #2701

Closed
dmlyons opened this issue Feb 6, 2020 · 8 comments · Fixed by #2703
Closed

go_auto_sameids causes gopls panic #2701

dmlyons opened this issue Feb 6, 2020 · 8 comments · Fixed by #2703

Comments

@dmlyons
Copy link

dmlyons commented Feb 6, 2020

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

Set cursor on iota in the following with let g:go_term_enabled = 1

package main

import "fmt"

const (
	foo = iota
	bar
)

func main() {
	fmt.Println("vim-go")
}

What did you expect to happen?

Nothing.

What happened instead?

gopls panicked:

{"method": "textDocument/didChange", "jsonrpc": "2.0", "params": {"contentChanges": [{"text": "package main\n\nimport \"fmt\"\n\nconst (\n\tfoo = iota\n\tbar\n)\n\nfunc main() {\n\tfmt.Println(\"vim-go\")\n}\n"}], "textDocument": {"uri": "file:///Users/*****/src/goplsbug/main.go", "version": 2}}}
sent: Content-Length: 233

{"method": "textDocument/references", "jsonrpc": "2.0", "id": 2, "params": {"context": {"includeDeclaration": true}, "textDocument": {"uri": "file:///Users/*****/src/goplsbug/main.go"}, "position": {"character": 12, "line": 0}}}
received: Content-Length: 90

{"jsonrpc":"2.0","error":{"code":0,"message":"no object for \"main\"","data":null},"id":2}
sent: Content-Length: 302

{"method": "textDocument/didChange", "jsonrpc": "2.0", "params": {"contentChanges": [{"text": "package main\n\nimport \"fmt\"\n\nconst (\n\tfoo = iota\n\tbar\n)\n\nfunc main() {\n\tfmt.Println(\"vim-go\")\n}\n"}], "textDocument": {"uri": "file:///Users/*****/src/goplsbug/main.go", "version": 3}}}
sent: Content-Length: 232

{"method": "textDocument/references", "jsonrpc": "2.0", "id": 3, "params": {"context": {"includeDeclaration": true}, "textDocument": {"uri": "file:///Users/*****/src/goplsbug/main.go"}, "position": {"character": 0, "line": 1}}}
received: Content-Length: 87

{"jsonrpc":"2.0","error":{"code":0,"message":"no identifier found","data":null},"id":3}
sent: Content-Length: 302

{"method": "textDocument/didChange", "jsonrpc": "2.0", "params": {"contentChanges": [{"text": "package main\n\nimport \"fmt\"\n\nconst (\n\tfoo = iota\n\tbar\n)\n\nfunc main() {\n\tfmt.Println(\"vim-go\")\n}\n"}], "textDocument": {"uri": "file:///Users/*****/src/goplsbug/main.go", "version": 4}}}
sent: Content-Length: 232

{"method": "textDocument/references", "jsonrpc": "2.0", "id": 4, "params": {"context": {"includeDeclaration": true}, "textDocument": {"uri": "file:///Users/*****/src/goplsbug/main.go"}, "position": {"character": 0, "line": 1}}}
received: Content-Length: 87

{"jsonrpc":"2.0","error":{"code":0,"message":"no identifier found","data":null},"id":4}
sent: Content-Length: 302

{"method": "textDocument/didChange", "jsonrpc": "2.0", "params": {"contentChanges": [{"text": "package main\n\nimport \"fmt\"\n\nconst (\n\tfoo = iota\n\tbar\n)\n\nfunc main() {\n\tfmt.Println(\"vim-go\")\n}\n"}], "textDocument": {"uri": "file:///Users/*****/src/goplsbug/main.go", "version": 5}}}
sent: Content-Length: 232

{"method": "textDocument/references", "jsonrpc": "2.0", "id": 5, "params": {"context": {"includeDeclaration": true}, "textDocument": {"uri": "file:///Users/*****/src/goplsbug/main.go"}, "position": {"character": 0, "line": 1}}}
received: Content-Length: 87

{"jsonrpc":"2.0","error":{"code":0,"message":"no identifier found","data":null},"id":5}
sent: Content-Length: 302

{"method": "textDocument/didChange", "jsonrpc": "2.0", "params": {"contentChanges": [{"text": "package main\n\nimport \"fmt\"\n\nconst (\n\tfoo = iota\n\tbar\n)\n\nfunc main() {\n\tfmt.Println(\"vim-go\")\n}\n"}], "textDocument": {"uri": "file:///Users/*****/src/goplsbug/main.go", "version": 6}}}
sent: Content-Length: 232

{"method": "textDocument/references", "jsonrpc": "2.0", "id": 6, "params": {"context": {"includeDeclaration": true}, "textDocument": {"uri": "file:///Users/*****/src/goplsbug/main.go"}, "position": {"character": 0, "line": 1}}}
received: Content-Length: 87

{"jsonrpc":"2.0","error":{"code":0,"message":"no identifier found","data":null},"id":6}
sent: Content-Length: 302

{"method": "textDocument/didChange", "jsonrpc": "2.0", "params": {"contentChanges": [{"text": "package main\n\nimport \"fmt\"\n\nconst (\n\tfoo = iota\n\tbar\n)\n\nfunc main() {\n\tfmt.Println(\"vim-go\")\n}\n"}], "textDocument": {"uri": "file:///Users/*****/src/goplsbug/main.go", "version": 7}}}
sent: Content-Length: 232

{"method": "textDocument/references", "jsonrpc": "2.0", "id": 7, "params": {"context": {"includeDeclaration": true}, "textDocument": {"uri": "file:///Users/*****/src/goplsbug/main.go"}, "position": {"character": 0, "line": 1}}}
received: Content-Length: 87

{"jsonrpc":"2.0","error":{"code":0,"message":"no identifier found","data":null},"id":7}
sent: Content-Length: 302

{"method": "textDocument/didChange", "jsonrpc": "2.0", "params": {"contentChanges": [{"text": "package main\n\nimport \"fmt\"\n\nconst (\n\tfoo = iota\n\tbar\n)\n\nfunc main() {\n\tfmt.Println(\"vim-go\")\n}\n"}], "textDocument": {"uri": "file:///Users/*****/src/goplsbug/main.go", "version": 8}}}
sent: Content-Length: 232

{"method": "textDocument/references", "jsonrpc": "2.0", "id": 8, "params": {"context": {"includeDeclaration": true}, "textDocument": {"uri": "file:///Users/*****/src/goplsbug/main.go"}, "position": {"character": 8, "line": 5}}}
received: Content-Length: 121

{"jsonrpc":"2.0","error":{"code":-32603,"message":"method \"textDocument/references\" did not reply","data":null},"id":8}
stderr: panic: runtime error: invalid memory address or nil pointer dereference
stderr: [signal SIGSEGV: segmentation violation code=0x1 addr=0x58 pc=0x13ca0f8]
stderr: 
stderr: goroutine 1617 [running]:
stderr: golang.org/x/tools/internal/lsp/source.findFileInPackage(0x0, 0x0, 0x0, 0x0, 0x0, 0xc000611288, 0x16d98e0, 0x0, 0x0, 0x1)
stderr: 	/Users/*****/go/pkg/mod/golang.org/x/tools@v0.0.0-20200204151227-34c67990bfe7/internal/lsp/source/util.go:691 +0x108
stderr: golang.org/x/tools/internal/lsp/source.findMapperInPackage(0x1a68740, 0xc0001e1b80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc0002d8bc0)
stderr: 	/Users/*****/go/pkg/mod/golang.org/x/tools@v0.0.0-20200204151227-34c67990bfe7/internal/lsp/source/util.go:664 +0x15e
stderr: golang.org/x/tools/internal/lsp/source.posToMappedRange(0x1a68740, 0xc0001e1b80, 0x0, 0x0, 0x0, 0x4, 0x0, 0x0, 0x0, 0x0, ...)
stderr: 	/Users/*****/go/pkg/mod/golang.org/x/tools@v0.0.0-20200204151227-34c67990bfe7/internal/lsp/source/util.go:204 +0x15b
stderr: golang.org/x/tools/internal/lsp/source.nameToMappedRange(...)
stderr: 	/Users/*****/go/pkg/mod/golang.org/x/tools@v0.0.0-20200204151227-34c67990bfe7/internal/lsp/source/util.go:199
stderr: golang.org/x/tools/internal/lsp/source.objToMappedRange(0x1a68740, 0xc0001e1b80, 0x0, 0x0, 0x1a69140, 0xc0000cc1e0, 0x0, 0x0, 0x0, 0x0, ...)
stderr: 	/Users/*****/go/pkg/mod/golang.org/x/tools@v0.0.0-20200204151227-34c67990bfe7/internal/lsp/source/util.go:195 +0x11a
stderr: golang.org/x/tools/internal/lsp/source.References(0x1a551c0, 0xc0022c33e0, 0x1a65280, 0xc00069e540, 0x1a53200, 0xc00069e480, 0x4014000000000000, 0x4020000000000000, 0x1919901, 0x0, ...)
stderr: 	/Users/*****/go/pkg/mod/golang.org/x/tools@v0.0.0-20200204151227-34c67990bfe7/internal/lsp/source/references.go:46 +0xe34
stderr: golang.org/x/tools/internal/lsp.(*Server).references(0xc00022de30, 0x1a551c0, 0xc002286ea0, 0xc0022e3c70, 0xc0022e3c70, 0x0, 0x0, 0x0, 0xc000501130)
stderr: 	/Users/*****/go/pkg/mod/golang.org/x/tools@v0.0.0-20200204151227-34c67990bfe7/internal/lsp/references.go:31 +0x1e5
stderr: golang.org/x/tools/internal/lsp.(*Server).References(0xc00022de30, 0x1a551c0, 0xc002286ea0, 0xc0022e3c70, 0xc0022e3c70, 0x0, 0x0, 0xc00042f840, 0x90def960)
stderr: 	/Users/*****/go/pkg/mod/golang.org/x/tools@v0.0.0-20200204151227-34c67990bfe7/internal/lsp/server_gen.go:148 +0x4d
stderr: golang.org/x/tools/internal/lsp/protocol.serverHandler.Deliver(0x1a731c0, 0xc00022de30, 0x1a551c0, 0xc002286ea0, 0xc002240940, 0xc002286e00, 0xc002352960)
stderr: 	/Users/*****/go/pkg/mod/golang.org/x/tools@v0.0.0-20200204151227-34c67990bfe7/internal/lsp/protocol/tsserver.go:400 +0x2c0d
stderr: golang.org/x/tools/internal/jsonrpc2.(*Conn).Run.func1(0xc001797740, 0xc002240940, 0xc000285c20, 0x1a551c0, 0xc002286ea0, 0x0, 0x0, 0xc00246acf0)
stderr: 	/Users/*****/go/pkg/mod/golang.org/x/tools@v0.0.0-20200204151227-34c67990bfe7/internal/jsonrpc2/jsonrpc2.go:370 +0x170
stderr: created by golang.org/x/tools/internal/jsonrpc2.(*Conn).Run
stderr: 	/Users/*****/go/pkg/mod/golang.org/x/tools@v0.0.0-20200204151227-34c67990bfe7/internal/jsonrpc2/jsonrpc2.go:354 +0x877

Configuration (MUST fill this out):

vim-go version:

v1.22 downloaded today

vimrc you used to reproduce (use a minimal vimrc with other plugins disabled; do not link to a 2,000 line vimrc):

vimrc
set nocompatible
filetype off
set modelines=0
set hidden

" EX mode can blow me
nnoremap Q

call plug#begin('~/.vim/plugged')
" Add or remove your Plugs here:

" golang

Plug 'fatih/vim-go', { 'tag': '*', 'do': ':GoUpdateBinaries' }
let g:go_debug=["lsp", "shell-commands"]
let g:go_fmt_command = 'goimports'
let g:go_rename_command = 'gopls'
let g:go_auto_sameids = 1

call plug#end()
set cmdheight=2

Vim version (first three lines from :version):

NVIM v0.4.3
Build type: Release
LuaJIT 2.0.5

Go version (go version):

go version go1.13.7 darwin/amd64

Go environment

go env Output:
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/*****/Library/Caches/go-build"
GOENV="/Users/*****/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/*****/go"
GOPRIVATE="github.com/meshifyiot/*"
GOPROXY="https://proxy.golang.org"
GOROOT="/usr/local/Cellar/go/1.13.7/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.13.7/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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/2c/8zpk5xtd6yn33tzg1byy5khm0000gn/T/go-build113930910=/tmp/go-build -gno-record-gcc-switches -fno-common"

gopls version

gopls version Output:
golang.org/x/tools/gopls v0.3.1
    golang.org/x/tools/gopls@v0.3.1 h1:yNTWrf4gc4Or0UecjOas5pzOa3BL0WDDyKDV4Wz5VaM=
@stamblerre
Copy link
Contributor

Thanks for reporting this. I was able to reproduce with gopls at master, and I will mail a fix for it soon.

@dmlyons
Copy link
Author

dmlyons commented Feb 6, 2020

Thanks, was just working out how to test it in gopls to see if that was where the issue lived, and then was gonna file a bug with the go project, but @stamblerre picking it up is just as good 👍

@stamblerre
Copy link
Contributor

Yep, definitely gopls's fault. https://go-review.googlesource.com/c/tools/+/218317 should fix it.

gopherbot pushed a commit to golang/tools that referenced this issue Feb 6, 2020
fatih/vim-go#2701 contains a report of a panic
when finding references on a builtin. Avoid this by simply not returning
any references.

Change-Id: I195fcb4502634201888f0c65022c9d16169cc1f3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/218317
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
@dmlyons
Copy link
Author

dmlyons commented Feb 6, 2020

ok, I manually made the change from that, and now it is producing a new error, but no panic, this may be vim-go:

Error detected while processing function <SNR>42_on_stdout[1]..<SNR>42_neocb[58]..4[13]..6[26]..<SNR>40_sameIDsHandler:
line    8:
E714: List required

@dmlyons
Copy link
Author

dmlyons commented Feb 6, 2020

Same result with current gopls master

@stamblerre
Copy link
Contributor

Yeah, I do think that looks like a vim-go error.

bhcleek added a commit to bhcleek/vim-go that referenced this issue Feb 7, 2020
Handle some null arrays to avoid errors.

Fixes fatih#2701
gopherbot pushed a commit to golang/tools that referenced this issue Feb 12, 2020
fatih/vim-go#2701 contains a report of a panic
when finding references on a builtin. Avoid this by simply not returning
any references.

Change-Id: I195fcb4502634201888f0c65022c9d16169cc1f3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/218317
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
(cherry picked from commit 222e5d4)
Reviewed-on: https://go-review.googlesource.com/c/tools/+/219123
@davegallant
Copy link

davegallant commented Mar 29, 2020

I'm still hitting this on gopls v0.3.4 using NVIM v0.4.3

I mitigated this error this by changing let g:go_auto_sameids = 1 to let g:go_auto_sameids = 0 in ~/.config/nvim/init.vim

@bhcleek
Copy link
Collaborator

bhcleek commented Mar 31, 2020

@davegallant FWIW we don't typically monitor closed issues.

However, if you're still having problems, please file an issue if you're experiencing this on the latest vim-go master.

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

Successfully merging a pull request may close this issue.

4 participants