API

class lsp.LanguageServer(protocol: 'LspProtocol[JsonRpcRequest[Any]]' = <factory>, _serve_task: 'asyncio.Task[None] | None' = None, _netcat_task: 'asyncio.Task[None] | None' = None, _listening_on: 'int | None' = None, _shutdown_received: 'bool' = False)
async wait() None
serve(std: bool = True, port: int = 0) AsyncIterator[Self]
abstract async initialize(params: InitializeParams) InitializeResult

The initialize request is sent as the first request from the client to the server. If the server receives a request or notification before the initialize request it should act as follows:

  • For a request the response should be an error with code: -32002. The message can be picked by the server.

  • Notifications should be dropped, except for the exit notification. This will allow the exit of a server without an initialize request.

async shutdown(params: None) None

The shutdown request is sent from the client to the server. It asks the server to shut down, but to not exit (otherwise the response might not be delivered correctly to the client). There is a separate exit() notification that asks the server to exit. Clients must not send any notifications other than exit or requests to a server to which they have sent a shutdown request. Clients should also wait with sending the exit notification until they have received a response from the shutdown request.

async exit(params: None) None

A notification to ask the server to exit its process. The server should exit with success code 0 if the shutdown request has been received before; otherwise with error code 1.

async text_document__declaration(params: DeclarationParams) Location | list[lsp.lsp.common.Location] | list[lsp.lsp.common.LocationLink] | None

The go to declaration request is sent from the client to the server to resolve the declaration location of a symbol at a given text document position.

async text_document__definition(params: DefinitionParams) Location | list[lsp.lsp.common.Location] | list[lsp.lsp.common.LocationLink] | None
async text_document__type_definition(params: TypeDefinitionParams) Location | list[lsp.lsp.common.Location] | list[lsp.lsp.common.LocationLink] | None
async text_document__implementation(params: ImplementationParams) Location | list[lsp.lsp.common.Location] | list[lsp.lsp.common.LocationLink] | None
async text_document__references(params: ReferenceParams) list[lsp.lsp.common.Location] | None
async text_document__prepare_call_hierarchy(params: CallHierarchyPrepareParams) list[lsp.lsp.server.CallHierarchyItem] | None
async call_hierarchy__incoming_calls(params: CallHierarchyIncomingCallsParams) list[lsp.lsp.server.CallHierarchyIncomingCall] | None
async call_hierarchy__outgoing_calls(params: CallHierarchyOutgoingCallsParams) list[lsp.lsp.server.CallHierarchyOutgoingCall] | None
async text_document__prepare_type_hierarchy(params: TypeHierarchyPrepareParams) list[lsp.lsp.server.TypeHierarchyItem] | None
async type_hierarchy__supertypes(params: TypeHierarchySupertypesParams) list[lsp.lsp.server.TypeHierarchyItem] | None
async type_hierarchy__subtypes(params: TypeHierarchySubtypesParams) list[lsp.lsp.server.TypeHierarchyItem] | None
async text_document__document_highlight(params: DocumentHighlightParams) list[lsp.lsp.server.DocumentHighlight] | None
async text_document__hover(params: HoverParams) Hover | None
async text_document__code_lens(params: CodeLensParams) CodeLens | None
async code_lens__resolve(params: CodeLens) CodeLens
async text_document__folding_range(params: FoldingRangeParams) list[lsp.lsp.server.FoldingRange] | None
async text_document__selection_range(params: SelectionRangeParams) list[lsp.lsp.server.SelectionRange] | None
async text_document__document_symbol(params: DocumentSymbolParam) list[lsp.lsp.server.DocumentSymbol] | list[lsp.lsp.server.SymbolInformation] | None
async text_document__semantic_tokens__full(params: SemanticTokensParams) SemanticTokens | None
async text_document__semantic_tokens__full__delta(params: SemanticTokensDeltaParams) SemanticTokens | SemanticTokensDelta | None
async text_document__semantic_tokens__range(params: SemanticTokensRangeParams) SemanticTokens | None
async text_document__inline_value(params: InlineValueParams) list[lsp.lsp.server.InlineValueText | lsp.lsp.server.InlineValueVariableLookup | lsp.lsp.server.InlineValueEvaluatableExpression] | None
async text_document__inlay_hint(params: InlayHintParams) list[lsp.lsp.server.InlayHint] | None
async inlay_hint__resolve(params: InlayHint) InlayHint
async text_document__moniker(params: MonikerParams) list[lsp.lsp.server.Moniker] | None
async text_document__completion(params: CompletionParams) list[lsp.lsp.server.CompletionItem] | CompletionList | None
async completion_item__resolve(params: CompletionItem) CompletionItem
async text_document__signature_help(params: SignatureHelpParams) SignatureHelp | None
async text_document__code_action(params: CodeActionParams) list[lsp.lsp.server.Command | lsp.lsp.server.CodeAction] | None
async code_action__resolve(params: CodeAction) CodeAction
async text_document__document_color(params: DocumentColorParams) list[lsp.lsp.server.ColorInformation]
async text_document__formatting(params: DocumentFormattingParams) list[lsp.lsp.server.TextEdit] | None
async workspace__execute_command(params: ExecuteCommandParams) Any | None
async initialized(params: InitializedParams) None
async text_document__did_open(params: DidOpenTextDocumentParams) None
async text_document__did_change(params: DidChangeTextDocumentParams) None
async text_document__will_save(params: WillSaveTextDocumentParams) None
async text_document__will_save_wait_until(params: WillSaveTextDocumentParams) list[lsp.lsp.server.TextEdit] | None
async text_document__did_save(params: DidSaveTextDocumentParams) None
async text_document__did_close(params: DidCloseTextDocumentParams) None
class lsp.protocol.LspProtocol

Bases: BufferedProtocol, Generic[T_Content]

Implement the base protocol for lanaguge server protocol messages.

async read_message() Message[T_Content]

Return the next availible JsonRpcRequest Message

write_message(msg: Message[JsonRpcResponse[Any] | JsonRpcRequest[Any]]) None

Write a jsonrpc Message

class lsp.protocol.Message(content: 'T_Content', content_type: 'str | None' = None, _content_bytes: 'bytes | None' = None, _content_len: 'int | None' = None)

Language Server Protocol Messages