Mercurial > vim
diff src/testdir/test_channel_lsp.py @ 33318:41e2414d2886 v9.0.1924
patch 9.0.1924: LSP server message still wrongly handled (after 9.0.1922)
Commit: https://github.com/vim/vim/commit/1926ae41845c3b6e2045b29225365c8a2e4eb1da
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Thu Sep 21 16:36:28 2023 +0200
patch 9.0.1924: LSP server message still wrongly handled (after 9.0.1922)
Problem: LSP server message still wrongly handled (after 9.0.1922)
Solution: Handle 'method' messages properly, don't discard them, add
tests.
closes: #13141
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 21 Sep 2023 16:45:06 +0200 |
parents | dd8da8f1c2bc |
children |
line wrap: on
line diff
--- a/src/testdir/test_channel_lsp.py +++ b/src/testdir/test_channel_lsp.py @@ -29,7 +29,20 @@ class ThreadedTCPRequestHandler(socketse with open("Xlspserver.log", "a") as myfile: myfile.write(msg) - def send_lsp_msg(self, msgid, resp_dict): + def send_lsp_req(self, msgid, method, params): + v = {'jsonrpc': '2.0', 'id': msgid, 'method': method} + if len(params) != 0: + v['params'] = params + s = json.dumps(v) + req = "Content-Length: " + str(len(s)) + "\r\n" + req += "Content-Type: application/vscode-jsonrpc; charset=utf-8\r\n" + req += "\r\n" + req += s + if self.debug: + self.debuglog("SEND: ({0} bytes) '{1}'\n".format(len(req), req)) + self.request.sendall(req.encode('utf-8')) + + def send_lsp_resp(self, msgid, resp_dict): v = {'jsonrpc': '2.0', 'result': resp_dict} if msgid != -1: v['id'] = msgid @@ -118,56 +131,56 @@ class ThreadedTCPRequestHandler(socketse def do_ping(self, payload): time.sleep(0.2) - self.send_lsp_msg(payload['id'], 'alive') + self.send_lsp_resp(payload['id'], 'alive') def do_echo(self, payload): - self.send_lsp_msg(-1, payload) + self.send_lsp_resp(-1, payload) def do_simple_rpc(self, payload): # test for a simple RPC request - self.send_lsp_msg(payload['id'], 'simple-rpc') + self.send_lsp_resp(payload['id'], 'simple-rpc') def do_rpc_with_notif(self, payload): # test for sending a notification before replying to a request message - self.send_lsp_msg(-1, 'rpc-with-notif-notif') + self.send_lsp_resp(-1, 'rpc-with-notif-notif') # sleep for some time to make sure the notification is delivered time.sleep(0.2) - self.send_lsp_msg(payload['id'], 'rpc-with-notif-resp') + self.send_lsp_resp(payload['id'], 'rpc-with-notif-resp') def do_wrong_payload(self, payload): # test for sending a non dict payload self.send_wrong_payload() time.sleep(0.2) - self.send_lsp_msg(-1, 'wrong-payload') + self.send_lsp_resp(-1, 'wrong-payload') def do_large_payload(self, payload): # test for sending a large (> 64K) payload - self.send_lsp_msg(payload['id'], payload) + self.send_lsp_resp(payload['id'], payload) def do_rpc_resp_incorrect_id(self, payload): - self.send_lsp_msg(-1, 'rpc-resp-incorrect-id-1') - self.send_lsp_msg(-1, 'rpc-resp-incorrect-id-2') - self.send_lsp_msg(1, 'rpc-resp-incorrect-id-3') + self.send_lsp_resp(-1, 'rpc-resp-incorrect-id-1') + self.send_lsp_resp(-1, 'rpc-resp-incorrect-id-2') + self.send_lsp_resp(1, 'rpc-resp-incorrect-id-3') time.sleep(0.2) - self.send_lsp_msg(payload['id'], 'rpc-resp-incorrect-id-4') + self.send_lsp_resp(payload['id'], 'rpc-resp-incorrect-id-4') def do_simple_notif(self, payload): # notification message test - self.send_lsp_msg(-1, 'simple-notif') + self.send_lsp_resp(-1, 'simple-notif') def do_multi_notif(self, payload): # send multiple notifications - self.send_lsp_msg(-1, 'multi-notif1') - self.send_lsp_msg(-1, 'multi-notif2') + self.send_lsp_resp(-1, 'multi-notif1') + self.send_lsp_resp(-1, 'multi-notif2') def do_msg_with_id(self, payload): - self.send_lsp_msg(payload['id'], 'msg-with-id') + self.send_lsp_resp(payload['id'], 'msg-with-id') def do_msg_specific_cb(self, payload): - self.send_lsp_msg(payload['id'], 'msg-specific-cb') + self.send_lsp_resp(payload['id'], 'msg-specific-cb') def do_server_req(self, payload): - self.send_lsp_msg(201, {'method': 'checkhealth', 'params': {'a': 20}}) + self.send_lsp_resp(201, {'method': 'checkhealth', 'params': {'a': 20}}) def do_extra_hdr_fields(self, payload): self.send_extra_hdr_fields(payload['id'], 'extra-hdr-fields') @@ -190,6 +203,19 @@ class ThreadedTCPRequestHandler(socketse def do_empty_payload(self, payload): self.send_empty_payload() + def do_server_req_in_middle(self, payload): + # Send a notification message to the client in the middle of processing + # a request message from the client + self.send_lsp_req(-1, 'server-req-in-middle', {'text': 'server-notif'}) + # Send a request message to the client in the middle of processing a + # request message from the client. + self.send_lsp_req(payload['id'], 'server-req-in-middle', {'text': 'server-req'}) + + def do_server_req_in_middle_resp(self, payload): + # After receiving a response from the client send the response to the + # client request. + self.send_lsp_resp(payload['id'], {'text': 'server-resp'}) + def process_msg(self, msg): try: decoded = json.loads(msg) @@ -213,7 +239,9 @@ class ThreadedTCPRequestHandler(socketse 'hdr-with-wrong-len': self.do_hdr_with_wrong_len, 'hdr-with-negative-len': self.do_hdr_with_negative_len, 'empty-header': self.do_empty_header, - 'empty-payload': self.do_empty_payload + 'empty-payload': self.do_empty_payload, + 'server-req-in-middle': self.do_server_req_in_middle, + 'server-req-in-middle-resp': self.do_server_req_in_middle_resp, } if decoded['method'] in test_map: test_map[decoded['method']](decoded)