scry icon indicating copy to clipboard operation
scry copied to clipboard

Intellij-Idea LSP protocol mismatch

Open Blacksmoke16 opened this issue 8 years ago • 13 comments

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

image

image

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":["???","???","???","???","???","???","???"]}}

Blacksmoke16 avatar Mar 31 '18 00:03 Blacksmoke16

/cc @crystal-lang-tools/scry

faustinoaq avatar Mar 31 '18 00:03 faustinoaq

Seems the initialize message sended by intellij-idea client is a bit different:

  1. 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"
    }
}
  1. 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": {}
            }
        }
    }
}

faustinoaq avatar Mar 31 '18 00:03 faustinoaq

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.

keplersj avatar Mar 31 '18 05:03 keplersj

/cc @gtache

keplersj avatar Mar 31 '18 05:03 keplersj

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 avatar Mar 31 '18 12:03 kofno

@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 avatar Mar 31 '18 17:03 keplersj

@keplersj agreed. We should fix.

kofno avatar Mar 31 '18 17:03 kofno

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

keplersj avatar Mar 31 '18 17:03 keplersj

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

faustinoaq avatar Apr 09 '18 16:04 faustinoaq

Any updates on this?

malte-v avatar Feb 11 '19 19:02 malte-v

Oh I totally forgot about this. I can check it when i get home tonight.

Blacksmoke16 avatar Feb 11 '19 19:02 Blacksmoke16

@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 avatar Feb 13 '19 00:02 Blacksmoke16

@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.

malte-v avatar Feb 13 '19 06:02 malte-v