Intellij-Idea LSP protocol mismatch
OS: Linux 4.9.0-6-amd64 #1 SMP Debian 4.9.82-1+deb9u3 (2018-03-02) x86_64 GNU/Linux
IDE: RubyMine 2017.3.3
Plugin: https://plugins.jetbrains.com/plugin/10209-lsp-support


scry.out.tHN1QZ
I, [2018-03-30 20:08:56 -04:00 #16188] INFO -- : Scry is looking into your code...
D, [2018-03-30 20:08:56 -04:00 #16188] DEBUG -- : Content-Length: 586
D, [2018-03-30 20:08:56 -04:00 #16188] DEBUG -- :
D, [2018-03-30 20:08:56 -04:00 #16188] DEBUG -- : {"jsonrpc":"2.0","id":"1","method":"initialize","params":{"rootUri":"file:///api_v2/","capabilities":{"workspace":{"applyEdit":true,"workspaceEdit":{"documentChanges":true},"didChangeWatchedFiles":{},"symbol":{},"executeCommand":{}},"textDocument":{"synchronization":{"willSave":true,"willSaveWaitUntil":true,"didSave":true},"completion":{"completionItem":{"snippetSupport":false}},"hover":{},"signatureHelp":{},"references":{},"documentHighlight":{},"formatting":{},"rangeFormatting":{},"onTypeFormatting":{},"definition":{},"codeAction":{},"rename":{}}}}}
D, [2018-03-30 20:08:56 -04:00 #16188] DEBUG -- : Content SEND: Content-Length: 839
{"jsonrpc":"2.0","error":{"code":-32001,"message":"Couldn't parse (Scry::NotificationMessage | Scry::RequestMessage) from {\"jsonrpc\":\"2.0\",\"id\":\"1\",\"method\":\"initialize\",\"params\":{\"rootUri\":\"file:///api_v2/\",\"capabilities\":{\"workspace\":{\"applyEdit\":true,\"workspaceEdit\":{\"documentChanges\":true},\"didChangeWatchedFiles\":{},\"symbol\":{},\"executeCommand\":{}},\"textDocument\":{\"synchronization\":{\"willSave\":true,\"willSaveWaitUntil\":true,\"didSave\":true},\"completion\":{\"completionItem\":{\"snippetSupport\":false}},\"hover\":{},\"signatureHelp\":{},\"references\":{},\"documentHighlight\":{},\"formatting\":{},\"rangeFormatting\":{},\"onTypeFormatting\":{},\"definition\":{},\"codeAction\":{},\"rename\":{}}}}} at 1:1","data":["???","???","???","???","???","???","???"]}}
/cc @crystal-lang-tools/scry
Seems the initialize message sended by intellij-idea client is a bit different:
- Message sent by a working client (VSCode)
{
"jsonrpc": "2.0",
"id": 0,
"method": "initialize",
"params": {
"processId": 8075,
"rootPath": "/home/main/Projects/console",
"rootUri": "file:///home/main/Projects/console",
"capabilities": {
"workspace": {
"didChangeConfiguration": {
"dynamicRegistration": true
},
"didChangeWatchedFiles": {
"dynamicRegistration": true
},
"symbol": {
"dynamicRegistration": true
},
"executeCommand": {
"dynamicRegistration": true
}
},
"textDocument": {
"synchronization": {
"dynamicRegistration": true,
"willSave": true,
"willSaveWaitUntil": true,
"didSave": true
},
"completion": {
"dynamicRegistration": true,
"completionItem": {
"snippetSupport": true
}
},
"hover": {
"dynamicRegistration": true
},
"signatureHelp": {
"dynamicRegistration": true
},
"definition": {
"dynamicRegistration": true
},
"references": {
"dynamicRegistration": true
},
"documentHighlight": {
"dynamicRegistration": true
},
"documentSymbol": {
"dynamicRegistration": true
},
"codeAction": {
"dynamicRegistration": true
},
"codeLens": {
"dynamicRegistration": true
},
"formatting": {
"dynamicRegistration": true
},
"rangeFormatting": {
"dynamicRegistration": true
},
"onTypeFormatting": {
"dynamicRegistration": true
},
"rename": {
"dynamicRegistration": true
},
"documentLink": {
"dynamicRegistration": true
}
}
},
"trace": "off"
}
}
- Message sent by intellij LSP client (extracted from this issue)
{
"jsonrpc": "2.0",
"id": "1",
"method": "initialize",
"params": {
"rootUri": "file:///api_v2/",
"capabilities": {
"workspace": {
"applyEdit": true,
"workspaceEdit": {
"documentChanges": true
},
"didChangeWatchedFiles": {},
"symbol": {},
"executeCommand": {}
},
"textDocument": {
"synchronization": {
"willSave": true,
"willSaveWaitUntil": true,
"didSave": true
},
"completion": {
"completionItem": {
"snippetSupport": false
}
},
"hover": {},
"signatureHelp": {},
"references": {},
"documentHighlight": {},
"formatting": {},
"rangeFormatting": {},
"onTypeFormatting": {},
"definition": {},
"codeAction": {},
"rename": {}
}
}
}
}
I don't think this is technically an issue with scry. I think this issue falls on intellij-lsp. It looks to me that intellij-lsp is not in compliance with the protocol. Once they are compliant scry should work.
/cc @gtache
Is it true that this isn't a scry problem? Which part of that message are we failing on? According to the 3.0 spec, many of those fields (hover, etc) should be optional. Which means the intellij message may be valid and scry isn't compliant.
@kofno I think you're right, looking back it it.
Here's the TypeScript definition in the spec for hover:
/**
* Capabilities specific to the `textDocument/hover`
*/
hover?: {
/**
* Whether hover supports dynamic registration.
*/
dynamicRegistration?: boolean;
/**
* Client supports the follow content formats for the content
* property. The order describes the preferred format of the client.
*/
contentFormat?: MarkupKind[];
};
Given this it looks like valid values for the hover field would include hover: undefined, hover: null, hover: {}, and hover: { dynamicRegistration: true }.
@keplersj agreed. We should fix.
So I just went to see how we've mapped the schema for capabilities and we have capabilities mapped to JSON::Any
https://github.com/crystal-lang-tools/scry/blob/master/src/scry/protocol/initialize_params.cr#L8
So I'm not so sure capabilities is the problem anymore. It looks like our mapping of processId and rootPath is incorrect.
/**
* The process Id of the parent process that started
* the server. Is null if the process has not been started by another process.
* If the parent process is not alive then the server should exit (see exit notification) its process.
*/
processId: number | null;
/**
* The rootPath of the workspace. Is null
* if no folder is open.
*
* @deprecated in favour of rootUri.
*/
rootPath?: string | null;
https://github.com/crystal-lang-tools/scry/blob/master/src/scry/protocol/initialize_params.cr#L6-L7
Hi @Blacksmoke16 We merged a PR to fix InitializeParams :tada:
Can you test it again in your Intellij-Idea IDE?
You will need to compile scry from master branch, try this:
git clone https://github.com/crystal-lang-tools/scry.git
cd scry
mkdir bin
crystal build --status --progress src/scry.cr -o bin/scry
Any updates on this?
Oh I totally forgot about this. I can check it when i get home tonight.
@faustinoaq @maltevoos I tried this again but same error. I used the latest release binary. I don't remember where the logs for this get outputted to tho....
@Blacksmoke16 Sorry, I meant to ask the devs if they could look into this once more because I had the same issue with the latest release.