Endpoint used to handle sending and receiving messages to and from the language server. This object runs as a separate thread from the rest of the application to allow it to always be listening for responses from the server.
json_rpc_endpoint : JsonRpcEndpoint JsonRpcEndpoint
Protocol used to assist in sending JSON messages to and from the language server.
method_callbacks : Dict[str, Callable]
Collection of callbacks to run when the endpoint receives the response to a method call. Each callback is keyed by the notification is listens for.
notify_callbacks : Dict[str, Callable]
Collection of callbacks to run when the endpoint receives specific notifications. Each callback is keyed by the notification is listens for.
event_dict : Dict[int, threading.Condition]
Dictionary holding multithreaded locks for waiting methods. Each lock is keyed by the index of the called method.
response_dict : Dict[int, Any]
Dictionary holding the results of method calls, keyed by the ID of the method call.
next_id : int
The next ID to be used when calling a method. Gets incremented by 1 after each call.
timeout : int
Max time to wait for the language server to respond to a method call.
shutdown_flag : bool
Whether the server should be signaled to shutdown.
diagnostics : Dict[str, List[Diagnostic]] Diagnostic
Contains all diagnostics keyed by the current file URI. Updated whenever the endpoint receives the
"textDocument/publishDiagnostics"method call.
__init__(self, json_rpc_endpoint, method_callbacks = {}, notify_callbacks = {}, timeout = 2)Creates a new LspEndpoint to communicate with a language server.
json_rpc_endpoint : JsonRpcEndpointJsonRpcEndpointProtocol used to assist in sending JSON messages to and from the language server.
method_callbacks : Dict = {}Optional. Collection of callbacks to run when the endpoint receives the response to a method call. Defaults to empty.
notify_callbacks : Dict = {}Optional. Collection of callbacks to run when the endpoint receives specific notifications. Defaults to empty.
timeout : int = 2Optional. Max time to wait for the language server to respond to a method call. Defaults to 2.
handle_result(self, rpc_id: int, result, error) -> NoneTakes the data received from the language server, adds it to the
response_dictattribute associated withrpc_id, then sets the lock associated withrpc_idto notify any awaiting method handlers that the method is completed.
rpc_id : intID of the sent message.
result : AnyResult received from the language server.
error : AnyAny errors received from the language server.
stop(self) -> NoneHalts the endpoint.
run(self) -> NoneInitiates the endpoint to listen for messages over
json_rpc_endpointand handle any messages that arrive.Raises:
ResponseErrorResponseError: If the language server attempts to call a method on the client which is not defined inmethod_callbacks, theMethodNotFounderror code is used.
send_response(self, id: int, result, error) -> NoneSends a response message back to the language server specified by
id.
id : intID of the method called by the language server.
resultResult of handling the method.
errorAny errors created in handling the method.
send_message(self, method_name: str, params, id: Optional[int] = None) -> NoneSends a message to the language server. Messages are specific types of requests where the server does not respond.
method_name : strName of the lsp method to call.
paramsParameters to pass to the method.
id : Optional[int] = NoneOptional. ID of the method for tracking the server's response. Defaults to None.
call_method(self, method_name: str, **kwargs) -> AnySends a message to the language server and awaits a response. If
timeoutis reached, the method fails.
method_name : strName of the lsp method to call.
**kwargsParameters to pass to the method.
Returns:
AnyThe response received from the language server.Raises:
TimeoutError: If the method call takes longer to respond than the timeout.ResponseErrorResponseError: If the server returns an error from the method call.
send_notification(self, method_name, **kwargs) -> NoneSends a message to the language server.
method_name : strName of the lsp method to call.
**kwargsParameters to pass to the method.