crystal-lang-tools/scry

Broken JSON-RPC message

rwols opened this issue · 3 comments

rwols commented

Hi there. According to the JSON-RPC spec, a response must contain an id key that is either a string or an integer. However, when scry encounters an error it'll put null as the value for id. This breaks the LSP package from Sublime Text.

In particular, when following the tutorial of crystal, I have this file:

puts "Hello World!"

in a file called hello_world.cr. I'm using 0.8.1 of scry.

When I then format this file with textDocument/formatting, scry returns the following payload:

{'jsonrpc': '2.0', 'error': {'data': ['Scry::start:(IO+ | Nil)', 'main'], 'code': -32001, 'message': 'Couldn\'t parse (Scry::Protocol::NotificationMessage | Scry::Protocol::RequestMessage) from {"jsonrpc":"2.0","params":{"workDoneToken":"wd2","options":{"tabSize":4,"trimTrailingWhitespace":false,"trimFinalNewlines":true,"insertSpaces":true,"insertFinalNewline":true},"textDocument":{"uri":"file:///Users/raoulwols/dev/crystal-hello-world/hello_world.cr"}},"method":"textDocument/formatting","id":2} at 1:1'}, 'id': None}

As you can see the id here is null.

rwols commented

c.f. https://www.jsonrpc.org/specification#response_object

id
This member is REQUIRED.
It MUST be the same as the value of the id member in the Request Object.
If there was an error in detecting the id in the Request object (e.g. Parse error/Invalid Request), it MUST be Null.

rwols commented

Hmm, so it says it should be null when it couldn't detect the id in the request object. There is an id in the request object:

{"jsonrpc":"2.0","params":{"workDoneToken":"wd2","options":{"tabSize":4,"trimTrailingWhitespace":false,"trimFinalNewlines":true,"insertSpaces":true,"insertFinalNewline":true},"textDocument":{"uri":"file:///Users/raoulwols/dev/crystal-hello-world/hello_world.cr"}},"method":"textDocument/formatting","id":2}
rwols commented

I'm not that well-versed in crystal but it looks like it's supposed to parse the id from the request message:

https://github.com/crystal-lang-tools/lsp/blob/master/src/lsp/protocol/request_message.cr

not sure what's up then. By the way, id may also be a string, not just an Int32.