LSP integration
Language servers run as child processes speaking JSON-RPC over stdio. Message types come from lsp-types, framing from lsp-server (both maintained by the rust-analyzer project). The client itself is small and lives in ide-languages::lsp.
Threads and blocking
Each server has a writer thread (owns stdin), a reader thread (owns stdout) and a stderr thread that keeps the last 40 lines for crash reports. Requests return immediately; responses and notifications are queued and delivered when the UI calls poll. The only blocking call is the bounded shutdown on exit.
Requests the server sends to the client are answered by the reader thread so the server never waits on the UI: workspace/configuration returns defaults, registration and progress requests are acknowledged, unknown methods get MethodNotFound.
Protocol details
| Topic | Behaviour |
|---|---|
| Position encoding | UTF-16 (advertised explicitly; conversions in ide-text). |
| Document sync | Incremental when the server supports it, otherwise full text; didSave is sent so rust-analyzer runs cargo check. |
| Versions | Derived from the document revision; diagnostics for an older version are dropped. |
| Definition | textDocument/definition; Location, Location[] and LocationLink[] are accepted; the first result is opened. |
| Timeouts | Initialisation 60 s, requests 10 s (then $/cancelRequest). |
| Crashes | Reported with the first stderr line; restarted with backoff while documents need the server, up to 3 times unless it had run stably for 2 minutes. |
| Missing server | Reported once per workspace; syntax features keep working. |
Testing without a real server
ide-fake-lsp is a deterministic server used by CI. It reports an error for every ERROR in a document (in UTF-16 columns, so multibyte text is exercised), resolves definitions of fn name/function name, exits on CRASH_NOW, and can advertise full sync (--full-sync). A real rust-analyzer test exists but is opt-in.