emacs-lsp
emacs-lsp copied to clipboard
Line numbers are off by one
See cursor position is on callOptionFunc but the hover string (in the way bottom) is for SetMeta, which is on the line below.

The Go lang server trace shows:
$ langserver-go -mode tcp -trace
langserver-go: listening on :4389
--> request #1071513773664973755: initialize: {"capabilities":null,"processId":null,"rootPath":"/home/sqs/src/github.com/sourcegraph/jsonrpc2/","initializationOptions":null}
<-- result #1071513773664973755: initialize: {"capabilities":{"textDocumentSync":1,"hoverProvider":true,"definitionProvider":true,"referencesProvider":true,"documentSymbolProvider":true,"workspaceSymbolProvider":true}}
...
--> request #79049804191771228: textDocument/hover: {"textDocument":{"uri":"file:///home/sqs/src/github.com/sourcegraph/jsonrpc2/call_opt.go"},"position":{"line":17,"character":16}}
<-- result #79049804191771228: textDocument/hover: {"contents":[{"language":"go","value":"func (*Request).SetMeta(v interface{}) error"},{"language":"markdown","value":"SetMeta sets r.Meta to the JSON representation of v. If JSON marshaling fails, it returns an error. \n\n"}],"range":{"start":{"line":17,"character":11},"end":{"line":17,"character":18}}}
See that the textDocument/hover request's line is 17 (which is indeed the line number if you are counting line numbers starting at 1). Per the LSP spec (https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#position), the line number is zero-based. This means that the request should have asked for line 16, not 17.
- Send zero-based line number
- The column number is ALSO 0-based, so the same adjustment needs to be applied to make the column number zero-based.
- When the LSP adapter gets an LSP response with a position, it needs to convert the zero-based response data to 1-indexed numbers for Emacs.
(Note: I was only able to get this to work by hackily removing all calls to textDocument/didOpen, as necessitated by #5. So, you should fix that before this.)