Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot get server to respond to Initialize request #708

Closed
mtangoo opened this issue Mar 28, 2019 · 3 comments
Closed

Cannot get server to respond to Initialize request #708

mtangoo opened this issue Mar 28, 2019 · 3 comments

Comments

@mtangoo
Copy link

mtangoo commented Mar 28, 2019

I'm toying around LSP and I cannot get past first stage. Am using Python as client language since it is simple to work with. All I do is:

Connect to LSP - This works fine
Send Initialize JSON RPC - Client report success
Get response - Empty result

I have tried everything I could and read whatever I could find but I had no success. I hope for someone more conversant with LSP to help me pointing out what am doing wrong.

Here is the JSON

{
    "jsonrpc": "2.0",
    "id": 1,
    "method": " initialize",
    "params": {
        "processId": null,
        "rootPath": "/Users/stefano/Testing/PHPSources",
        "rootUri": "file:///Users/stefano/Testing/PHPSources",
        "capabilities": {
            "workspace": {
                "applyEdit": true,
                "workspaceEdit": {
                    "documentChanges": true,
                    "resourceOperations": [
                        "create",
                        "rename",
                        "delete"
                    ],
                    "failureHandling": "textOnlyTransactional"
                },
                "didChangeConfiguration": {
                    "dynamicRegistration": true
                },
                "didChangeWatchedFiles": {
                    "dynamicRegistration": true
                },
                "symbol": {
                    "dynamicRegistration": true,
                    "symbolKind": {
                        "valueSet": [
                            1,
                            2,
                            3,
                            4,
                            5,
                            6,
                            7,
                            8,
                            9,
                            10,
                            11,
                            12,
                            13,
                            14,
                            15,
                            16,
                            17,
                            18,
                            19,
                            20,
                            21,
                            22,
                            23,
                            24,
                            25,
                            26
                        ]
                    }
                },
                "executeCommand": {
                    "dynamicRegistration": true
                },
                "configuration": true,
                "workspaceFolders": true
            },
            "textDocument": {
                "publishDiagnostics": {
                    "relatedInformation": true,
                    "tagSupport": true
                },
                "synchronization": {
                    "dynamicRegistration": true,
                    "willSave": true,
                    "willSaveWaitUntil": true,
                    "didSave": true
                },
                "completion": {
                    "dynamicRegistration": true,
                    "contextSupport": true,
                    "completionItem": {
                        "snippetSupport": true,
                        "commitCharactersSupport": true,
                        "documentationFormat": [
                            "markdown",
                            "plaintext"
                        ],
                        "deprecatedSupport": true,
                        "preselectSupport": true
                    },
                    "completionItemKind": {
                        "valueSet": [
                            1,
                            2,
                            3,
                            4,
                            5,
                            6,
                            7,
                            8,
                            9,
                            10,
                            11,
                            12,
                            13,
                            14,
                            15,
                            16,
                            17,
                            18,
                            19,
                            20,
                            21,
                            22,
                            23,
                            24,
                            25
                        ]
                    }
                },
                "hover": {
                    "dynamicRegistration": true,
                    "contentFormat": [
                        "markdown",
                        "plaintext"
                    ]
                },
                "signatureHelp": {
                    "dynamicRegistration": true,
                    "signatureInformation": {
                        "documentationFormat": [
                            "markdown",
                            "plaintext"
                        ],
                        "parameterInformation": {
                            "labelOffsetSupport": true
                        }
                    }
                },
                "definition": {
                    "dynamicRegistration": true,
                    "linkSupport": true
                },
                "references": {
                    "dynamicRegistration": true
                },
                "documentHighlight": {
                    "dynamicRegistration": true
                },
                "documentSymbol": {
                    "dynamicRegistration": true,
                    "symbolKind": {
                        "valueSet": [
                            1,
                            2,
                            3,
                            4,
                            5,
                            6,
                            7,
                            8,
                            9,
                            10,
                            11,
                            12,
                            13,
                            14,
                            15,
                            16,
                            17,
                            18,
                            19,
                            20,
                            21,
                            22,
                            23,
                            24,
                            25,
                            26
                        ]
                    },
                    "hierarchicalDocumentSymbolSupport": true
                },
                "codeAction": {
                    "dynamicRegistration": true,
                    "codeActionLiteralSupport": {
                        "codeActionKind": {
                            "valueSet": [
                                "",
                                "quickfix",
                                "refactor",
                                "refactor.extract",
                                "refactor.inline",
                                "refactor.rewrite",
                                "source",
                                "source.organizeImports"
                            ]
                        }
                    }
                },
                "codeLens": {
                    "dynamicRegistration": true
                },
                "formatting": {
                    "dynamicRegistration": true
                },
                "rangeFormatting": {
                    "dynamicRegistration": true
                },
                "onTypeFormatting": {
                    "dynamicRegistration": true
                },
                "rename": {
                    "dynamicRegistration": true,
                    "prepareSupport": true
                },
                "documentLink": {
                    "dynamicRegistration": true
                },
                "typeDefinition": {
                    "dynamicRegistration": true,
                    "linkSupport": true
                },
                "implementation": {
                    "dynamicRegistration": true,
                    "linkSupport": true
                },
                "colorProvider": {
                    "dynamicRegistration": true
                },
                "foldingRange": {
                    "dynamicRegistration": true,
                    "rangeLimit": 5000,
                    "lineFoldingOnly": true
                },
                "declaration": {
                    "dynamicRegistration": true,
                    "linkSupport": true
                }
            }
        },
        "initializationOptions": {
            "storagePath": "/Users/hosanna/Library/Application Support/Code/User/workspaceStorage/30bd6a399166f4f329c9f383d63b74ca/bmewburn.vscode-intelephense-client",
            "clearCache": false
        },
        "trace": "verbose",
        "workspaceFolders": [
            {
                "uri": "file:///Users/stefano/Testing/PHPSources",
                "name": "TransportationApp"
            }
        ]
    }
}

Here is my full Python code. I tried with PHP Language Server but shouldn't matter the kind of server used.

import socket
import sys 

initReq = """
{
    "jsonrpc": "2.0",
    "id": 1,
    "method": " initialize",
    "params": {
        "processId": null,
        "rootPath": "/Users/stefano/Testing/PHPSources",
        "rootUri": "file:///Users/stefano/Testing/PHPSources",
        "capabilities": {
            "workspace": {
                "applyEdit": true,
                "workspaceEdit": {
                    "documentChanges": true,
                    "resourceOperations": [
                        "create",
                        "rename",
                        "delete"
                    ],
                    "failureHandling": "textOnlyTransactional"
                },
                "didChangeConfiguration": {
                    "dynamicRegistration": true
                },
                "didChangeWatchedFiles": {
                    "dynamicRegistration": true
                },
                "symbol": {
                    "dynamicRegistration": true,
                    "symbolKind": {
                        "valueSet": [
                            1,
                            2,
                            3,
                            4,
                            5,
                            6,
                            7,
                            8,
                            9,
                            10,
                            11,
                            12,
                            13,
                            14,
                            15,
                            16,
                            17,
                            18,
                            19,
                            20,
                            21,
                            22,
                            23,
                            24,
                            25,
                            26
                        ]
                    }
                },
                "executeCommand": {
                    "dynamicRegistration": true
                },
                "configuration": true,
                "workspaceFolders": true
            },
            "textDocument": {
                "publishDiagnostics": {
                    "relatedInformation": true,
                    "tagSupport": true
                },
                "synchronization": {
                    "dynamicRegistration": true,
                    "willSave": true,
                    "willSaveWaitUntil": true,
                    "didSave": true
                },
                "completion": {
                    "dynamicRegistration": true,
                    "contextSupport": true,
                    "completionItem": {
                        "snippetSupport": true,
                        "commitCharactersSupport": true,
                        "documentationFormat": [
                            "markdown",
                            "plaintext"
                        ],
                        "deprecatedSupport": true,
                        "preselectSupport": true
                    },
                    "completionItemKind": {
                        "valueSet": [
                            1,
                            2,
                            3,
                            4,
                            5,
                            6,
                            7,
                            8,
                            9,
                            10,
                            11,
                            12,
                            13,
                            14,
                            15,
                            16,
                            17,
                            18,
                            19,
                            20,
                            21,
                            22,
                            23,
                            24,
                            25
                        ]
                    }
                },
                "hover": {
                    "dynamicRegistration": true,
                    "contentFormat": [
                        "markdown",
                        "plaintext"
                    ]
                },
                "signatureHelp": {
                    "dynamicRegistration": true,
                    "signatureInformation": {
                        "documentationFormat": [
                            "markdown",
                            "plaintext"
                        ],
                        "parameterInformation": {
                            "labelOffsetSupport": true
                        }
                    }
                },
                "definition": {
                    "dynamicRegistration": true,
                    "linkSupport": true
                },
                "references": {
                    "dynamicRegistration": true
                },
                "documentHighlight": {
                    "dynamicRegistration": true
                },
                "documentSymbol": {
                    "dynamicRegistration": true,
                    "symbolKind": {
                        "valueSet": [
                            1,
                            2,
                            3,
                            4,
                            5,
                            6,
                            7,
                            8,
                            9,
                            10,
                            11,
                            12,
                            13,
                            14,
                            15,
                            16,
                            17,
                            18,
                            19,
                            20,
                            21,
                            22,
                            23,
                            24,
                            25,
                            26
                        ]
                    },
                    "hierarchicalDocumentSymbolSupport": true
                },
                "codeAction": {
                    "dynamicRegistration": true,
                    "codeActionLiteralSupport": {
                        "codeActionKind": {
                            "valueSet": [
                                "",
                                "quickfix",
                                "refactor",
                                "refactor.extract",
                                "refactor.inline",
                                "refactor.rewrite",
                                "source",
                                "source.organizeImports"
                            ]
                        }
                    }
                },
                "codeLens": {
                    "dynamicRegistration": true
                },
                "formatting": {
                    "dynamicRegistration": true
                },
                "rangeFormatting": {
                    "dynamicRegistration": true
                },
                "onTypeFormatting": {
                    "dynamicRegistration": true
                },
                "rename": {
                    "dynamicRegistration": true,
                    "prepareSupport": true
                },
                "documentLink": {
                    "dynamicRegistration": true
                },
                "typeDefinition": {
                    "dynamicRegistration": true,
                    "linkSupport": true
                },
                "implementation": {
                    "dynamicRegistration": true,
                    "linkSupport": true
                },
                "colorProvider": {
                    "dynamicRegistration": true
                },
                "foldingRange": {
                    "dynamicRegistration": true,
                    "rangeLimit": 5000,
                    "lineFoldingOnly": true
                },
                "declaration": {
                    "dynamicRegistration": true,
                    "linkSupport": true
                }
            }
        },
        "initializationOptions": {
            "storagePath": "/Users/hosanna/Library/Application Support/Code/User/workspaceStorage/30bd6a399166f4f329c9f383d63b74ca/bmewburn.vscode-intelephense-client",
            "clearCache": false
        },
        "trace": "verbose",
        "workspaceFolders": [
            {
                "uri": "file:///Users/stefano/Testing/PHPSources",
                "name": "TransportationApp"
            }
        ]
    }
}
"""

host = '127.0.0.1'
port = 8088

# create socket
print('# Creating socket')
try:
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error:
    print('Failed to create socket')
    sys.exit()

# Connect to remote server
print('# Connecting to server, ' + host)
s.connect((host , port))

# Send data to remote server
print('# Sending data to server')

try:
    s.sendall(initReq.encode('utf-8'))
except socket.error:
    print('Send failed')
    sys.exit()

# Receive data
print('# Receive data from server')
reply = s.recv(4096)

print(reply) 

I apologize if the policy is for reporting bugs only here. I read some issues asking qustions, so I assumed I can ask questions here!

@rcjsuen
Copy link
Contributor

rcjsuen commented Mar 28, 2019

@mtangoo I don't understand what you mean by:

Get response - Empty result

Did you send a request and the server sent you back an empty JSON or something? I suggest you show the exact output of everything in your Python script. I would also suggest truncating your code to not send such a big a payload to initialize. There's a lot of vertical scrolling involved here and the less you send the less variables you're including in your message (possibility for typos and so on).

In any case, from a cursory glance I get the feeling that your message isn't including a Content-Length header and all that good stuff.

The following is taken from the specification:

Content-Length: ...\r\n
\r\n
{
	"jsonrpc": "2.0",
	"id": 1,
	"method": "textDocument/didOpen",
	"params": {
		...
	}
}

@mtangoo
Copy link
Author

mtangoo commented Mar 28, 2019

Did you send a request and the server sent you back an empty JSON or something?

I mean the result of print is empty.

In any case, from a cursory glance I get the feeling that your message isn't including a Content-Length header and all that good stuff.
The following is taken from the specification:

Oh! my bad. How did I miss that? Let me add these and comment back

@mtangoo
Copy link
Author

mtangoo commented Mar 28, 2019

@rcjsuen that was it. I have added the header and all is well now. Thank you

@mtangoo mtangoo closed this as completed Mar 28, 2019
@vscodebot vscodebot bot locked and limited conversation to collaborators May 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants