textDocument/didOpen needs to include file contents
Hovers and other ops fail with errors like:
Ignored LSP error: ((code . 0) (message . "invalid position: /home/sqs/src/github.com/sourcegraph/jsonrpc2/jsonrpc2.go:59:23 (character 23 is beyond first line boundary)") (data))
...
Ignored LSP error: ((code . 0) (message . "/home/sqs/src/github.com/sourcegraph/jsonrpc2/jsonrpc2.go:1:1: expected 'package', found 'EOF'") (data))
I believe this is because the lang server thinks the jsonrpc2.go file is empty. The trace from the Go lang server confirms this:
$ langserver-go -mode tcp -trace
langserver-go: listening on :4389
--> request #1329760234113517669: initialize: {"capabilities":null,"processId":null,"rootPath":"/home/sqs/src/github.com/sourcegraph/jsonrpc2/","initializationOptions":null}
<-- result #1329760234113517669: initialize: {"capabilities":{"textDocumentSync":1,"hoverProvider":true,"definitionProvider":true,"referencesProvider":true,"documentSymbolProvider":true,"workspaceSymbolProvider":true}}
--> request #1369339415339987355: textDocument/didOpen: {"textDocument":{"uri":"file:///home/sqs/src/github.com/sourcegraph/jsonrpc2/jsonrpc2.go"}}
<-- result #1369339415339987355: textDocument/didOpen: {}
--> request #1459730796359449849: textDocument/hover: {"textDocument":{"uri":"file:///home/sqs/src/github.com/sourcegraph/jsonrpc2/jsonrpc2.go"},"position":{"line":59,"character":23}}
<-- error #1459730796359449849: textDocument/hover: {"code":0,"message":"invalid position: /home/sqs/src/github.com/sourcegraph/jsonrpc2/jsonrpc2.go:59:23 (character 23 is beyond first line boundary)","data":null}
--> request #1301260603960974227: textDocument/hover: {"textDocument":{"uri":"file:///home/sqs/src/github.com/sourcegraph/jsonrpc2/jsonrpc2.go"},"position":{"line":59,"character":15}}
<-- error #1301260603960974227: textDocument/hover: {"code":0,"message":"invalid position: /home/sqs/src/github.com/sourcegraph/jsonrpc2/jsonrpc2.go:59:15 (character 15 is beyond first line boundary)","data":null}
--> request #1307285885937006797: textDocument/hover: {"textDocument":{"uri":"file:///home/sqs/src/github.com/sourcegraph/jsonrpc2/jsonrpc2.go"},"position":{"line":58,"character":6}}
<-- error #1307285885937006797: textDocument/hover: {"code":0,"message":"invalid position: /home/sqs/src/github.com/sourcegraph/jsonrpc2/jsonrpc2.go:58:6 (character 6 is beyond first line boundary)","data":null}
--> request #1614299885607679516: textDocument/hover: {"textDocument":{"uri":"file:///home/sqs/src/github.com/sourcegraph/jsonrpc2/call_opt.go"},"position":{"line":17,"character":16}}
<-- error #1614299885607679516: textDocument/hover: {"code":0,"message":"/home/sqs/src/github.com/sourcegraph/jsonrpc2/jsonrpc2.go:1:1: expected 'package', found 'EOF'","data":null}
Note that the textDocument/didOpen request includes a uri but no text. The LSP spec at https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#textdocumentitem requires text to be included. Since it's missing, I believe the Go lang server is interpreting that to mean the document is empty. (The Go lang server should technically return an error, since the text field must exist, but even if it did that, this emacs LSP adapter still needs to be changed to send the text field.)
Fix: Send over the full document text in the text field of TextDocumentItem.