saibing / bingo

Bingo is a Go language server that speaks Language Server Protocol.
MIT License
495 stars 25 forks source link

False positive error on parameter types #89

Closed lggomez closed 5 years ago

lggomez commented 5 years ago

Unfortunately I couldn't come up with a simple repro, this happens at work (VS Code):

screen shot 2019-02-08 at 14 50 15

This builds successfully from console

mbana commented 5 years ago

You said you cannot come up with a reproducible test case. Can you share the output when you run bingo with -trace enabled?

tanordheim commented 5 years ago

I'm seeing some of these as well - I'm looking through the trace output here now and my findings are:

The first occurence of the false posistive happens after a save after editing for a while:

--> notif: textDocument/didSave: {"textDocument":{"uri":"file:///Users/REDACTED/myapp/moderate/service_test.go","version":524}}
<-- notif: textDocument/publishDiagnostics: {"uri":"file:///Users/REDACTED/myapp/moderate/service_test.go","diagnostics":[{"range":{"start":{"line":103,"character":27},"end":{"line":103,"character":27}},"severity":1,"source":"LSP: Go compiler","message":"cannot use (func(topicID myapp.TopicID, postID myapp.PostID) (*myapp.Post, error) literal) (value of type func(topicID gitlab.com/REDACTED/myapp.TopicID, postID gitlab.com/REDACTED/myapp.PostID) (*gitlab.com/REDACTED/myapp.Post, error)) as func(topicID gitlab.com/REDACTED/myapp.TopicID, id gitlab.com/REDACTED/myapp.PostID) (*gitlab.com/REDACTED/myapp.Post, error) value in assignment"},{"range":{"start":{"line":108,"character":29},"end":{"line":108,"character":29}},"severity":1,"source":"LSP: Go compiler","message":"cannot use (func(_ *myapp.Post) error literal) (value of type func(_ *gitlab.com/REDACTED/myapp.Post) error) as func(in1 *gitlab.com/REDACTED/myapp.Post) error value in assignment"},{"range":{"start":{"line":44,"character":34},"end":{"line":44,"character":34}},"severity":1,"source":"LSP: Go compiler","message":"cannot use (func(topicID myapp.TopicID, postID myapp.PostID) error literal) (value of type func(topicID gitlab.com/REDACTED/myapp.TopicID, postID gitlab.com/REDACTED/myapp.PostID) error) as func(topicID gitlab.com/REDACTED/myapp.TopicID, postID gitlab.com/REDACTED/myapp.PostID) error value in assignment"}]}

After this starts occuring I start seeing some panics in my logs - but it happens quite a lot later so I don't know if they are neccessarily related:

--> notif: textDocument/didChange: {"textDocument":{"uri":"file:///Users/REDACTED/myapp/write/service.go","version":4},"contentChanges":[{"range":{"start":{"line":0,"character":2},"end":{"line":0,"character":2}},"rangeLength":0,"text":"c"}]}
invalid position for file 
panic serving textDocument/completion: runtime error: invalid memory address or nil pointer dereference
goroutine 6388 [running]:
github.com/saibing/bingo/langserver/internal/util.Panicf(0x451f8e0, 0x49eae00, 0x45b080c, 0x2, 0xc007e1b7f8, 0x1, 0x1, 0xc007e1b808, 0x405ba66)
    /opt/bingo/359e4f9a910dd1949e4419d41d39ba9057fc675c/langserver/internal/util/util.go:116 +0x93
github.com/saibing/bingo/langserver.(*LangHandler).Handle.func1(0xc00a4359a0, 0xc007e1be60)
    /opt/bingo/359e4f9a910dd1949e4419d41d39ba9057fc675c/langserver/handler.go:110 +0xc4
panic(0x451f8e0, 0x49eae00)
    /usr/local/Cellar/go/1.11.5/libexec/src/runtime/panic.go:513 +0x1b9
go/token.(*File).Size(...)
    /usr/local/Cellar/go/1.11.5/libexec/src/go/token/position.go:120
github.com/saibing/bingo/langserver.lineStart(0x0, 0x1, 0xc0165ebce0)
    /opt/bingo/359e4f9a910dd1949e4419d41d39ba9057fc675c/langserver/position.go:76 +0x37
github.com/saibing/bingo/langserver.fromProtocolPosition(0x0, 0x0, 0x2, 0xc01133c4c0)
    /opt/bingo/359e4f9a910dd1949e4419d41d39ba9057fc675c/langserver/position.go:49 +0x38
github.com/saibing/bingo/langserver.(*LangHandler).handleTextDocumentCompletion(0xc0000e2420, 0x4668e20, 0xc0146267c0, 0x4667220, 0xc00012a500, 0xc00a4359a0, 0xc01133c480, 0x39, 0x0, 0x2, ...)
    /opt/bingo/359e4f9a910dd1949e4419d41d39ba9057fc675c/langserver/completion.go:34 +0x10a
github.com/saibing/bingo/langserver.(*LangHandler).Handle(0xc0000e2420, 0x4668e20, 0xc0146267c0, 0x4667220, 0xc00012a500, 0xc00a4359a0, 0x0, 0x0, 0x0, 0x0)
    /opt/bingo/359e4f9a910dd1949e4419d41d39ba9057fc675c/langserver/handler.go:268 +0x267a
github.com/saibing/bingo/langserver.(*LangHandler).handle(0xc0000e2420, 0x4668e60, 0xc0000ac008, 0xc00012a500, 0xc00a4359a0, 0xc013cf2540, 0x3a, 0x0, 0x0)
    /opt/bingo/359e4f9a910dd1949e4419d41d39ba9057fc675c/langserver/handler.go:100 +0x66
github.com/saibing/bingo/langserver.(*LangHandler).handle-fm(0x4668e60, 0xc0000ac008, 0xc00012a500, 0xc00a4359a0, 0x0, 0x0, 0x0, 0x0)
    /opt/bingo/359e4f9a910dd1949e4419d41d39ba9057fc675c/langserver/handler.go:26 +0x52
github.com/sourcegraph/jsonrpc2.(*HandlerWithErrorConfigurer).Handle(0xc0000a33d0, 0x4668e60, 0xc0000ac008, 0xc00012a500, 0xc00a4359a0)
    /Users/REDACTED/go/pkg/mod/github.com/sourcegraph/jsonrpc2@v0.0.0-20180831160525-549eb959f029/handler_with_error.go:21 +0x73
created by github.com/saibing/bingo/langserver.lspHandler.Handle
    /opt/bingo/359e4f9a910dd1949e4419d41d39ba9057fc675c/langserver/handler.go:50 +0xfb
<-- error #420: textDocument/completion: {"code":0,"message":"unexpected panic: runtime error: invalid memory address or nil pointer dereference","data":null}
[Error - 2:59:13 PM] Request textDocument/completion failed.
  Message: unexpected panic: runtime error: invalid memory address or nil pointer dereference
  Code: 0 

I've tried anonymizing the output here a little bit, hopefully I haven't done anything that removes any important information from it. As mentiond by @lggomez the project builds successfully and restarting VSCode (and thus Bingo) solves the problem for a little while.

It's quite reproducible for me, happening 5-10 times per day. Is there any info I could provide to help pinpoint the issue?

Thanks.

tanordheim commented 5 years ago

I just updated to the recent master version and I'm still seeing the same issue. For me it seems to be quite consistently croaking when passing around mocks to functions requiring interfaces; for example:

This seems to start creating the issue more or less the first time I save a file as it is now.

It, however, does not seem to happen if I run bingo with -cache-style=none; might this be some cache corruption issue of some sort?

lggomez commented 5 years ago

@tanordheim yeah, this is pretty much my case

mbana commented 5 years ago

I notice similar issues when working with mocks. I will try to put together a full reproduction test case in a repository to demonstrate the issue. If anyone has already done so, please share it.

I am using https://github.com/mockery/mockery.

nezorflame commented 5 years ago

It seems that the latest version from master has fixed this issue! Can someone confirm this, or am I seeing things? :)

tanordheim commented 5 years ago

I don't think I've seen it since updating 5 days ago either; however, I've been working on a different project for the last few days with a different code structure (no generated mocks, which have been a source of problems before) so I can't fully say which one is the source of things working better. I'm moving back to that other project that were causing issues multiple times a day for me later this week, I can report back if I see any there.

nezorflame commented 5 years ago

Yup, I see it in my other project as well with the same problems.

tanordheim commented 5 years ago

I'm seeing this in some projects here still, after upgrading to the latest commit in master as of 24 hours ago. I'm struggling to reproduce it in a small self contained project I could give as a reproduction, but I'm happy to offer any information you'd need and test any work in progress changes with one of our code bases here where it happens quite regularly.

inliquid commented 5 years ago

Still having this problem: изображение

mbana commented 5 years ago

@saibing

I've made a lot of changes in this branch https://github.com/banaio/bingo/tree/fix_issues_with_textDocument/publishDiagnostics but I believe the core fix is in either or both of the below:

The rest of the changes are just refactoring. The entire diff of the branch is https://github.com/saibing/bingo/compare/master...banaio:fix_issues_with_textDocument/publishDiagnostics. I've tried to make the commits atomic so you can see changes incrementally. The tests do not pass hence the commit message saying it is a breaking change, run gotest -count=1 -v -json ./... to see where it gets stuck.

Also, I don't know if this makes a difference but I run a build with race detector enabled:

$ go build -o $GOPATH/bin/bingo_dev -race

If anyone wants to try the branch and report back that'd be great.


Edit:

// Handle implements jsonrpc2.Handler
func (h lspHandler) Handle(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) {
    // if isFileSystemRequest(req.Method) {
    //  h.Handler.Handle(ctx, conn, req)
    //  return
    // }
    go h.Handler.Handle(ctx, conn, req) // tests don't get stuck
    // h.Handler.Handle(ctx, conn, req) // tests get stuck
}
saibing commented 5 years ago

@lggomez @mbana @nezorflame @inliquid

Please use the enhanced version of gopls, it has fixed this issue.