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.
- Child
Guard - Owns the child process; killing on drop so no server outlives the editor.
- Completion
Item - One completion candidate.
- Diagnostic
- One server diagnostic (0-based line, protocol severity 1=error..4=hint).
- Framing
Reader - Parse
Content-Length-framed messages from any buffered reader. - LspClient
- A ready-to-use server connection for one editor session.
- Stdio
Transport - 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_OVERRIDEreplaces 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/configurationpull. The answer is the requested SECTION VALUE (result[0]pairs withitems[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 noanalysisand silently drop (that exact shape starvedimport piteof 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-Lengthheaders. - find_
stubs_ dir - Walk up from
startlooking forpython/pite/pite.pyi(or a barepite.pyi); return the dir containing it — what goes onextraPathssoimport piteresolves to the shipped stubs. - hover_
request - initialize_
request initializecarrying the project root. Settings travel separately viadidChangeConfiguration(andworkspace/configurationanswers).- 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
publishDiagnosticsparams into diagnostics (empty when clean). - parse_
signature_ help - Parse signature help into one line per overload.
- parse_
version - First
major.minor.patchin free-form--versionoutput. - 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
initializehandshake 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 needsfile:///D:/dir/file.py— forward slashes and a leading slash before the drive letter. Emittingfile://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 forextraPaths.