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: panic when adding a comment at the end of a file #38793

Closed
0xd3e opened this issue May 1, 2020 · 5 comments
Closed

x/tools/gopls: panic when adding a comment at the end of a file #38793

0xd3e opened this issue May 1, 2020 · 5 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@0xd3e
Copy link

0xd3e commented May 1, 2020

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

$ go version
go version go1.14.2 darwin/amd64

$ gopls version
golang.org/x/tools/gopls 0.4.0
    golang.org/x/tools/gopls@v0.4.0 h1:G4+YP9kaV4dJb79J5MobyApxX493Qa6VoiTceUmxqik=

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="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/danieltrautmann/Library/Caches/go-build"
GOENV="/Users/danieltrautmann/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/danieltrautmann/Development/Go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.14.2_1/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.14.2_1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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/2r/xknybh5n1yjcz3kg_7pk44c00000gn/T/go-build408795356=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I use Neovim with the coc.nvim plugin to access the language server features.

coc.nvim config
{
	"coc.preferences.formatOnSaveFiletypes": ["go"],
	"diagnostic.virtualText": true,
	"languageserver": {
		"golang": {
			"command": "gopls",
			"args": ["-rpc.trace", "-logfile", "/Users/danieltrautmann/Desktop/gopls.log"],
			"rootPatterns": ["go.mod"],
			"filetypes": ["go"],
			"initializationOptions": {
				"completeUnimported": true,
				"usePlaceholders": true
			}
		}
	},
	"suggest.noselect": false
}

When I write a comment at the end of a file, gopls panics with panic: illegal line number.

It doesn't panic with an empty file when only the comment is added, but as soon as package name is added, gopls crashes when writing the first character after // that is not a space.

package mypkg

// H <---- gopls panics right after typing H

What did you expect to see?

gopls does not panic.

What did you see instead?

gopls panics and coc.nvim tries to restart it. If this fails 5 times within 3 minutes, coc.nvim will not try again and completion and other features are not available anymore.

coc.nvim shows something like this in its log:

2020-04-29T19:54:34.683 INFO (pid:30254) [services] - golang state change: running => stopped
2020-04-29T19:54:34.683 INFO (pid:30254) [services] - golang state change: stopped => starting
2020-04-29T19:54:34.684 INFO (pid:30254) [completion-complete] - Results from: around
2020-04-29T19:54:34.688 INFO (pid:30254) [language-client-index] - languageserver.golang started with 35522
2020-04-29T19:54:34.719 INFO (pid:30254) [services] - golang state change: starting => running
2020-04-29T19:54:35.473 INFO (pid:30254) [services] - golang state change: running => stopped
2020-04-29T19:54:35.473 INFO (pid:30254) [services] - golang state change: stopped => starting
2020-04-29T19:54:35.474 INFO (pid:30254) [completion-complete] - Results from: around
2020-04-29T19:54:35.477 INFO (pid:30254) [language-client-index] - languageserver.golang started with 35563
2020-04-29T19:54:35.507 INFO (pid:30254) [services] - golang state change: starting => running
2020-04-29T19:54:36.820 INFO (pid:30254) [services] - golang state change: running => stopped
2020-04-29T19:54:36.820 INFO (pid:30254) [services] - golang state change: stopped => starting
2020-04-29T19:54:36.821 INFO (pid:30254) [completion-complete] - Results from: around,buffer
2020-04-29T19:54:36.828 INFO (pid:30254) [language-client-index] - languageserver.golang started with 35626
2020-04-29T19:54:36.885 INFO (pid:30254) [services] - golang state change: starting => running
2020-04-29T19:54:50.795 INFO (pid:30254) [services] - golang state change: running => stopped
2020-04-29T19:54:50.795 INFO (pid:30254) [services] - golang state change: stopped => starting
2020-04-29T19:54:50.795 INFO (pid:30254) [completion-complete] - Results from: around,buffer
2020-04-29T19:54:50.799 INFO (pid:30254) [language-client-index] - languageserver.golang started with 35805
2020-04-29T19:54:50.828 INFO (pid:30254) [services] - golang state change: starting => running
2020-04-29T19:54:51.782 ERROR (pid:30254) [language-client-client] - The languageserver.golang server crashed 5 times in the last 3 minutes. The server will not be restarted.
@gopherbot gopherbot added this to the Unreleased milestone May 1, 2020
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels May 1, 2020
@gopherbot
Copy link

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.

@0xd3e
Copy link
Author

0xd3e commented May 1, 2020

This issue might be related to #37226

@heschi
Copy link
Contributor

heschi commented May 1, 2020

This area of the code has been a rich source of bugs, but I can't reproduce this one. If you can get the panic trace, I can probably fix it without a repro. I don't know how to do that in vim, sorry.

@0xd3e
Copy link
Author

0xd3e commented May 1, 2020

@heschik do you mean this one? I forgot to add it.

panic: illegal line number

goroutine 7464 [running]:
go/token.(File).LineStart(0xc003b44000, 0x25, 0x0)
	/usr/local/Cellar/go/1.14.21/libexec/src/go/token/position.go:222 +0xe8
golang.org/x/tools/internal/lsp/source.(completer).populateCommentCompletions(0xc008a14780, 0x1a40520, 0xc003c753e0, 0xc0084d0960)
	/Users/danieltrautmann/Development/Go/pkg/mod/golang.org/x/tools@v0.0.0-20200407041343-bf15fae40dea/internal/lsp/source/completion.go:697 +0x189
golang.org/x/tools/internal/lsp/source.Completion(0x1a40520, 0xc003c753e0, 0x1a51cc0, 0xc0000d6a10, 0x1a3eda0, 0xc00894c300, 0x4041800000000000, 0x4010000000000000, 0x0, 0x0, ...)
	/Users/danieltrautmann/Development/Go/pkg/mod/golang.org/x/tools@v0.0.0-20200407041343-bf15fae40dea/internal/lsp/source/completion.go:523 +0xb64
golang.org/x/tools/internal/lsp.(Server).completion(0xc000215580, 0x1a404a0, 0xc008590100, 0xc003c75380, 0x0, 0x0, 0xc00311bc30)
	/Users/danieltrautmann/Development/Go/pkg/mod/golang.org/x/tools@v0.0.0-20200407041343-bf15fae40dea/internal/lsp/completion.go:27 +0x6d7
golang.org/x/tools/internal/lsp.(Server).Completion(0xc000215580, 0x1a404a0, 0xc008590100, 0xc003c75380, 0xc003c75380, 0x0, 0x0)
	/Users/danieltrautmann/Development/Go/pkg/mod/golang.org/x/tools@v0.0.0-20200407041343-bf15fae40dea/internal/lsp/servergen.go:24 +0x49
golang.org/x/tools/internal/lsp/protocol.ServerHandler.func1(0x1a404a0, 0xc008590100, 0xc008590080, 0x1958dd8084, 0x1f7da40)
	/Users/danieltrautmann/Development/Go/pkg/mod/golang.org/x/tools@v0.0.0-20200407041343-bf15fae40dea/internal/lsp/protocol/tsserver.go:238 +0x1e0b
golang.org/x/tools/internal/lsp/lsprpc.handshaker.func1(0x1a404a0, 0xc008590100, 0xc008590080, 0x0, 0x0)
	/Users/danieltrautmann/Development/Go/pkg/mod/golang.org/x/tools@v0.0.0-20200407041343-bf15fae40dea/internal/lsp/lsprpc/lsprpc.go:531 +0x505
golang.org/x/tools/internal/jsonrpc2.MustReply.func1(0x1a404a0, 0xc008590100, 0xc008590080, 0xc001d6b100, 0x4ce)
	/Users/danieltrautmann/Development/Go/pkg/mod/golang.org/x/tools@v0.0.0-20200407041343-bf15fae40dea/internal/jsonrpc2/handler.go:54 +0x47
golang.org/x/tools/internal/jsonrpc2.AsyncHandler.func1.2(0xc003e9f860, 0xc0081433b0, 0xc0003667d0, 0x1a404a0, 0xc008590100, 0xc008590080)
	/Users/danieltrautmann/Development/Go/pkg/mod/golang.org/x/tools@v0.0.0-20200407041343-bf15fae40dea/internal/jsonrpc2/handler.go:110 +0x6c
created by golang.org/x/tools/internal/jsonrpc2.AsyncHandler.func1
	/Users/danieltrautmann/Development/Go/pkg/mod/golang.org/x/tools@v0.0.0-20200407041343-bf15fae40dea/internal/jsonrpc2/handler.go:107 +0x187

@stamblerre
Copy link
Contributor

Ah thank you for sharing the trace! Just added a comment to https://golang.org/cl/230215, so hopefully we can get it resolved as part of that change.

@stamblerre stamblerre modified the milestones: Unreleased, gopls/v0.5.0 May 2, 2020
@stamblerre stamblerre modified the milestones: gopls/v0.5.0, gopls/v0.4.1 May 13, 2020
@golang golang locked and limited conversation to collaborators May 13, 2021
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. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants