无法初始化语言服务器协议
Cannot Initialize Language Server Protocol
我在玩 LSP,我无法通过第一阶段。我使用 Python 作为客户端语言,因为它易于使用。我所做的只是:
- 连接到 LSP - 这工作正常
- 发送初始化JSON RPC - 客户端报告成功
- 获取响应 - 空结果
我已经尽我所能,阅读我能找到的一切,但我没有成功。我希望有人更熟悉 LSP 来帮助我指出做错了什么。
这是我的 Python 代码。我尝试使用 PHP Language Server,但使用的服务器类型无关紧要。
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)
我遗漏了页眉部分及其相应的新行。感谢rcjsuen for helping on Github
供参考的格式应该是:
Content-Length: <length>\r\n
\r\n
{
"jsonrpc": "2.0",
"id": 1,
"method": "textDocument/didOpen",
"params": {
...
}
}
我在玩 LSP,我无法通过第一阶段。我使用 Python 作为客户端语言,因为它易于使用。我所做的只是:
- 连接到 LSP - 这工作正常
- 发送初始化JSON RPC - 客户端报告成功
- 获取响应 - 空结果
我已经尽我所能,阅读我能找到的一切,但我没有成功。我希望有人更熟悉 LSP 来帮助我指出做错了什么。
这是我的 Python 代码。我尝试使用 PHP Language Server,但使用的服务器类型无关紧要。
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)
我遗漏了页眉部分及其相应的新行。感谢rcjsuen for helping on Github
供参考的格式应该是:
Content-Length: <length>\r\n
\r\n
{
"jsonrpc": "2.0",
"id": 1,
"method": "textDocument/didOpen",
"params": {
...
}
}