Fix memory leaks in LspEndpoint
This commit is contained in:
parent
b5d7829011
commit
59c48cdd62
@ -59,7 +59,7 @@ class LspEndpoint(threading.Thread):
|
|||||||
else:
|
else:
|
||||||
self.handle_result(rpc_id, result, error)
|
self.handle_result(rpc_id, result, error)
|
||||||
except lsp_structs.ResponseError as e:
|
except lsp_structs.ResponseError as e:
|
||||||
self.send_response(rpc_id, None, e)
|
self.send_response(rpc_id, None, e)
|
||||||
|
|
||||||
|
|
||||||
def send_response(self, id, result, error):
|
def send_response(self, id, result, error):
|
||||||
@ -71,7 +71,7 @@ class LspEndpoint(threading.Thread):
|
|||||||
if error:
|
if error:
|
||||||
message_dict["error"] = error
|
message_dict["error"] = error
|
||||||
self.json_rpc_endpoint.send_request(message_dict)
|
self.json_rpc_endpoint.send_request(message_dict)
|
||||||
|
|
||||||
|
|
||||||
def send_message(self, method_name, params, id = None):
|
def send_message(self, method_name, params, id = None):
|
||||||
message_dict = {}
|
message_dict = {}
|
||||||
@ -81,18 +81,21 @@ class LspEndpoint(threading.Thread):
|
|||||||
message_dict["method"] = method_name
|
message_dict["method"] = method_name
|
||||||
message_dict["params"] = params
|
message_dict["params"] = params
|
||||||
self.json_rpc_endpoint.send_request(message_dict)
|
self.json_rpc_endpoint.send_request(message_dict)
|
||||||
|
|
||||||
|
|
||||||
def call_method(self, method_name, **kwargs):
|
def call_method(self, method_name, **kwargs):
|
||||||
current_id = self.next_id
|
current_id = self.next_id
|
||||||
self.next_id += 1
|
self.next_id += 1
|
||||||
cond = threading.Condition()
|
cond = threading.Condition()
|
||||||
self.event_dict[current_id] = cond
|
self.event_dict[current_id] = cond
|
||||||
|
|
||||||
cond.acquire()
|
cond.acquire()
|
||||||
self.send_message(method_name, kwargs, current_id)
|
self.send_message(method_name, kwargs, current_id)
|
||||||
cond.wait()
|
cond.wait()
|
||||||
cond.release()
|
cond.release()
|
||||||
result, error = self.response_dict[current_id]
|
|
||||||
|
self.event_dict.pop(current_id)
|
||||||
|
result, error = self.response_dict.pop(current_id)
|
||||||
if error:
|
if error:
|
||||||
raise lsp_structs.ResponseError(error.get("code"), error.get("message"), error.get("data"))
|
raise lsp_structs.ResponseError(error.get("code"), error.get("message"), error.get("data"))
|
||||||
return result
|
return result
|
||||||
|
Loading…
Reference in New Issue
Block a user