Protocol
- class pygls.protocol.LanguageServerProtocol(server, converter)
A class that represents language server protocol.
It contains implementations for generic LSP features.
- Parameters:
server (LanguageServer) –
converter (Converter) –
- get_message_type(method)
Return LSP type definitions, as provided by
lsprotocol
- Parameters:
method (str) –
- Return type:
Type[Any] | None
- get_result_type(method)
Return the type definition of the result associated with the given method.
- Parameters:
method (str) –
- Return type:
Type[Any] | None
- lsp_exit(*args)
Stops the server process.
- Return type:
Generator[Any, Any, None]
- lsp_initialize(params)
Method that initializes language server. It will compute and return server capabilities based on registered features.
- Parameters:
params (types.InitializeParams) –
- Return type:
Generator[Any, Any, types.InitializeResult]
- lsp_initialized(*args)
Notification received when client and server are connected.
- lsp_notebook_document__did_change(params)
Update a notebook’s contents
- Parameters:
params (DidChangeNotebookDocumentParams) –
- lsp_notebook_document__did_close(params)
Remove a notebook document from the workspace.
- Parameters:
params (DidCloseNotebookDocumentParams) –
- lsp_notebook_document__did_open(params)
Put a notebook document into the workspace
- Parameters:
params (DidOpenNotebookDocumentParams) –
- lsp_set_trace(params)
Changes server trace value.
- Parameters:
params (types.SetTraceParams) –
- Return type:
Generator[Any, Any, None]
- lsp_shutdown(*args)
Request from client which asks server to shutdown.
- Return type:
Generator[Any, Any, None]
- lsp_text_document__did_change(params)
Updates document’s content. (Incremental(from server capabilities); not configurable for now)
- Parameters:
params (DidChangeTextDocumentParams) –
- lsp_text_document__did_close(params)
Removes document from workspace.
- Parameters:
params (DidCloseTextDocumentParams) –
- lsp_text_document__did_open(params)
Puts document to the workspace.
- Parameters:
params (DidOpenTextDocumentParams) –
- lsp_work_done_progress_cancel(params)
Received a progress cancellation from client.
- Parameters:
params (WorkDoneProgressCancelParams) –
- lsp_workspace__did_change_workspace_folders(params)
Adds/Removes folders from the workspace.
- Parameters:
params (DidChangeWorkspaceFoldersParams) –
- lsp_workspace__execute_command(params)
Executes commands with passed arguments and returns a value.
- Parameters:
params (types.ExecuteCommandParams) –
- Return type:
Generator[Any, Any, Any]
- class pygls.protocol.JsonRPCProtocol(server, converter)
Json RPC protocol implementation
Specification of the protocol can be found here: https://www.jsonrpc.org/specification
This class provides bidirectional communication which is needed for LSP.
- Parameters:
server (JsonRPCServer) –
converter (Converter) –
- get_message_type(method)
Return the type definition of the message associated with the given method.
- get_result_type(method)
Return the type definition of the result associated with the given method.
- handle_message(message)
Delegates message to handlers depending on message type.
- Parameters:
message (RPCNotification | RPCResponse | RPCRequest | RPCError) –
- notify(method, params=None)
Send a JSON-RPC notification.
Note
Notifications are “fire-and-forget”, there is no way for the recipient to respond directly to a notification. If you expect a response to this message, use
send_request
.
- send_request(method, params=None, callback=None, msg_id=None)
Send a JSON-RPC request
- Parameters:
method (str) – The method name of the message to send
params (Any | None) – The payload of the message
callback (Callable[[Any], None] | None) – If set, the given callback will be called with the result of the future when it resolves
msg_id (str | int | None) – Send the request using the given id, if
None
, an id will be automatically generated
- Returns:
A future that will resolve once a response has been received
- Return type:
Future[Any]
- send_request_async(method, params=None, msg_id=None)
Send a JSON-RPC request, asynchronously.
This method calls
send_request
, wrapping the resulting future withasyncio.wrap_future
so it can be used in anasync def
function and awaited with theawait
keyword.- Parameters:
method (str) – The method name of the message to send
params (Any | None) – The payload of the message
callback – If set, the given callback will be called with the result of the future when it resolves
msg_id (str | int | None) – Send the request using the given id, if
None
, an id will be automatically generated
- Return type:
asyncio.Future
that can be awaited
- set_writer(writer, include_headers=True)
Set the writer object to use when sending data
- Parameters:
writer (AsyncWriter | Writer) – The writer object
include_headers (bool) – Flag indicating if headers like
Content-Length
should be included when sending data. (DefaultTrue
)
- structure_message(data)
Function used to deserialize data recevied from the client.
- pygls.protocol.default_converter()
Default converter factory function.