From f57323e9e128c3f35c619d35a1478b0577bf097e Mon Sep 17 00:00:00 2001 From: Felipe Orozco Date: Thu, 15 Mar 2018 12:31:51 -0400 Subject: [PATCH] handle cancel correctly (#289) * handle cancel correctly * move paren --- pyls/rpc_manager.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pyls/rpc_manager.py b/pyls/rpc_manager.py index 2bc297d6..3015a8a3 100644 --- a/pyls/rpc_manager.py +++ b/pyls/rpc_manager.py @@ -10,11 +10,12 @@ from jsonrpc.exceptions import JSONRPCMethodNotFound, JSONRPCDispatchException, JSONRPCServerError log = logging.getLogger(__name__) - RESPONSE_CLASS_MAP = { "1.0": JSONRPC10Response, "2.0": JSONRPC20Response } +# as defined in https://github.com/Microsoft/language-server-protocol/blob/gh-pages/specification.md +LSP_CANCEL_CODE = -32800 class MissingMethodException(Exception): @@ -83,7 +84,9 @@ def cancel(self, request_id): """ log.debug('Cancel request %d', request_id) try: - self._received_requests[request_id].cancel() + self._received_requests[request_id].set_exception( + JSONRPCDispatchException(code=LSP_CANCEL_CODE, message="Request cancelled") + ) except KeyError: log.debug('Received cancel for finished/nonexistent request %d', request_id)