handle lifecycle in test server correctly

This commit is contained in:
Richard Howell
2019-08-28 11:01:25 -07:00
parent 301fa20327
commit 09552143be

View File

@@ -14,6 +14,7 @@ while True:
sys.stdin.readline()
message = json.loads(sys.stdin.read(length))
response = None
if message["method"] == "build/initialize":
response = {
"jsonrpc": "2.0",
@@ -29,18 +30,28 @@ while True:
}
}
}
# ignore notifications
elif message["method"] == "build/initialized":
continue
elif message["method"] == "build/shutdown":
response = {
"jsonrpc": "2.0",
"id": message["id"],
"result": None
}
elif message["method"] == "build/exit":
break
# ignore other notifications
elif "id" in message:
response = {
"jsonrpc": "2.0",
"id": message["id"],
"error": {
"code": 123,
"message": "unhandled method",
"message": "unhandled method {}".format(message["method"]),
}
}
responseStr = json.dumps(response)
sys.stdout.write("Content-Length: {}\r\n\r\n{}".format(len(responseStr), responseStr))
sys.stdout.flush()
if response:
responseStr = json.dumps(response)
sys.stdout.write("Content-Length: {}\r\n\r\n{}".format(len(responseStr), responseStr))
sys.stdout.flush()