Skip to main content

Module lsp

Module lsp 

Source
Expand description

External Python language server over stdio (pyright-family).

pite-editor never embeds a server: it spawns pyright-langserver --stdio (or PITE_LSP_CMD), syncs the code pane with didOpen/didChange, and surfaces completion, hover, signature help, and publishDiagnostics. The shipped pite.pyi stubs go on the server’s path so import pite resolves. No DAP, no bundled binary.

The protocol core is transport-agnostic: Bridge speaks JSON-RPC over any RpcTransport. Production uses StdioTransport (real child stdio); tests drive the same Bridge with a mock server.

Structs§

Bridge
Protocol state above a transport: request ids, pending kinds, typed results, and per-document diagnostics.
ChildGuard
Owns the child process; killing on drop so no server outlives the editor.
CompletionItem
One completion candidate.
Diagnostic
One server diagnostic (0-based line, protocol severity 1=error..4=hint).
FramingReader
Parse Content-Length-framed messages from any buffered reader.
LspClient
A ready-to-use server connection for one editor session.
StdioTransport
Real child-stdio transport: writes go straight to the server’s stdin, a reader thread forwards framed replies to a channel.

Enums§

LspOutcome
Starter outcome delivered to the UI thread.

Constants§

ENV_CMD_OVERRIDE
Env override for the server command (a binary name or path).
PINNED_PYRIGHT
Documented prerequisite; keep in sync with docs/lsp.md.
SERVER_ARGS
Args for the default command.
SERVER_CMD
Default server command; ENV_CMD_OVERRIDE replaces it.
STUBS_FILE
Shipped stubs file; its parent dir goes on the server’s extraPaths.

Traits§

RpcTransport
Byte transport for JSON-RPC values. Production speaks over child stdio; tests substitute a mock server speaking the same messages.

Functions§

byte_offset_of_char
Byte offset of a char offset (egui cursors count chars).
completion_request
configuration_response
Answer a server workspace/configuration pull. The answer is the requested SECTION VALUE (result[0] pairs with items[0]): for section "python" that is the {"analysis": ...} object itself — NOT wrapped in another "python" layer, which the server would read as a section with no analysis and silently drop (that exact shape starved import pite of its stubs). Anything else gets an empty object (defaults hold).
did_change_configuration
extraPaths + basic type-checking mode so the shipped stubs resolve.
did_change_notification
did_open_notification
encode_message
Frame a JSON-RPC value with Content-Length headers.
find_stubs_dir
Walk up from start looking for python/pite/pite.pyi (or a bare pite.pyi); return the dir containing it — what goes on extraPaths so import pite resolves to the shipped stubs.
hover_request
initialize_request
initialize carrying the project root. Settings travel separately via didChangeConfiguration (and workspace/configuration answers).
initialized_notification
line_start_byte
Byte offset of the start of 1-based line (clamped to end of text).
materialized_stubs_dir
Versioned scratch dir for the embedded stubs; the last resort behind find_stubs_dir, so a checkout’s own stubs always win.
missing_server_message
Loud message when no server is installed. Editing continues without LSP.
offset_to_position
(line, character) for an LSP position. Lines are 0-based; characters count UTF-16 code units per the protocol.
parse_completion_items
Parse a completion result (array or {items}; null means no candidates).
parse_hover
Parse a hover result into plain text (markdown fenced content included).
parse_publish_diagnostics
Parse publishDiagnostics params into diagnostics (empty when clean).
parse_signature_help
Parse signature help into one line per overload.
parse_version
First major.minor.patch in free-form --version output.
path_to_uri
Best-effort file:// URI for a path. Falls back to the raw path text when the current dir is unknown; servers only need it as a document key.
probe_server_version
Best-effort version probe: (version, warning). Never fails; a missing binary surfaces later at spawn with the loud message.
signature_request
spawn_lsp
Spawn the server in the background and run the initialize handshake there (cold starts take seconds). The receiver gets exactly one outcome; a missing binary fails fast and loudly, never silently.
uri_from_path_text
Build a file:// URI from an absolute path string, on any platform. Windows needs file:///D:/dir/file.py — forward slashes and a leading slash before the drive letter. Emitting file://D:\dir\file.py (naive concatenation) makes the server report the directory as nonexistent, so the conversion is explicit rather than string-pasted.
version_at_least
Numeric triple comparison against the pin.
word_end_after
End byte offset of the identifier starting at byte_offset (letters, digits, _); accepting mid-word replaces up to here.
word_start_before
Start byte offset of the identifier ending at byte_offset (letters, digits, _); completion replaces from here.
write_stubs_to
Write the embedded stubs into dir, skipping files that already match. Returns the dir for extraPaths.