Skip to content

LspClient

Source: leap0/_sync/lsp.py

LspClient(transport: Transport)

Start and interact with language servers for code intelligence inside a sandbox.

Supported languages: Python (pyright) and TypeScript/JavaScript (typescript-language-server).

The typical flow is start -> did_open -> completions or document_symbols -> did_close -> stop.

Attributes: None.

start(sandbox: SandboxRef, *, language_id: str, path_to_project: str) -> LspResponse

Start the LSP server for a language and project.

Spawns the server process and sends the LSP initialize handshake automatically.

Args: sandbox: Sandbox ID or object. language_id: Language identifier ("python", "typescript", or "javascript"). path_to_project: Project directory path inside the sandbox.

Returns: LspResponse: Server startup result.

stop(sandbox: SandboxRef, *, language_id: str, path_to_project: str) -> LspResponse

Send shutdown and exit to the language server and terminate it.

Args: sandbox: Sandbox ID or object. language_id: Language identifier for the LSP operation. path_to_project: Project path inside the sandbox.

Returns: object: Result returned by this operation.

did_open(sandbox: SandboxRef, *, language_id: str, path_to_project: str, uri: str, text: str | None = None, version: int = 1, http_timeout: float | None = None) -> None

Notify the language server that a document was opened.

Must be called before requesting completions or symbols.

Args: sandbox: Sandbox ID or object. language_id: Language identifier for the LSP operation. path_to_project: Project path inside the sandbox. uri: Document URI. text: Parameter for this operation. version: Parameter for this operation. http_timeout: Optional HTTP request timeout in seconds for this SDK call.

did_open_path(sandbox: SandboxRef, *, language_id: str, path_to_project: str, path: str, text: str | None = None, version: int = 1, http_timeout: float | None = None) -> None

Like :meth:did_open but accepts a file path instead of a URI.

Args: sandbox: Sandbox ID or object. language_id: Language identifier for the LSP operation. path_to_project: Project path inside the sandbox. path: File path inside the sandbox. text: Optional full document text to send with the open notification. version: Document version number. http_timeout: Optional HTTP request timeout in seconds for this SDK call.

did_close(sandbox: SandboxRef, *, language_id: str, path_to_project: str, uri: str, http_timeout: float | None = None) -> None

Notify the language server that a document was closed.

Args: sandbox: Sandbox ID or object. language_id: Language identifier for the LSP operation. path_to_project: Project path inside the sandbox. uri: Document URI.

did_close_path(sandbox: SandboxRef, *, language_id: str, path_to_project: str, path: str, http_timeout: float | None = None) -> None

Like :meth:did_close but accepts a file path instead of a URI.

Args: http_timeout: Optional HTTP request timeout in seconds for this SDK call.

completions(sandbox: SandboxRef, *, language_id: str, path_to_project: str, uri: str, line: int, character: int, http_timeout: float | None = None) -> LspJsonRpcResponse

Request completions from the language server.

Args: http_timeout: Optional HTTP request timeout in seconds for this SDK call.

Returns: LspJsonRpcResponse: Raw JSON-RPC response payload.

completions_path(sandbox: SandboxRef, *, language_id: str, path_to_project: str, path: str, line: int, character: int, http_timeout: float | None = None) -> LspJsonRpcResponse

Like :meth:completions but accepts a file path instead of a URI.

Args: http_timeout: Optional HTTP request timeout in seconds for this SDK call.

Returns: object: Result returned by this operation.

document_symbols(sandbox: SandboxRef, *, language_id: str, path_to_project: str, uri: str, http_timeout: float | None = None) -> LspJsonRpcResponse

Request document symbols from the language server.

Args: http_timeout: Optional HTTP request timeout in seconds for this SDK call.

Returns: LspJsonRpcResponse: Raw JSON-RPC response payload.

document_symbols_path(sandbox: SandboxRef, *, language_id: str, path_to_project: str, path: str, http_timeout: float | None = None) -> LspJsonRpcResponse

Like :meth:document_symbols but accepts a file path instead of a URI.

Args: http_timeout: Optional HTTP request timeout in seconds for this SDK call.

Returns: object: Result returned by this operation.