9. The language server and editors#

tempest lsp is a language server: an editor starts it, talks to it over stdin and stdout, and gets errors as you type, hover, go to definition, completion, find references, rename, an outline, and signature help. It answers from the same Analysis as the playground, so both always agree. editors/vscode/ holds a VS Code extension that starts it, with TextMate grammars for highlighting.

JSON-RPC over stdiodiagnostics, answersVS Code: extension.ts,vscode-languageclienttempest lsp: serveOpen documentsSources: memory layer,then disk, std built inThe library around a fileSettleAnalysisPlayground: wasm
JSON-RPC over stdiodiagnostics, answersVS Code: extension.ts,vscode-languageclienttempest lsp: serveOpen documentsSources: memory layer,then disk, std built inThe library around a fileSettleAnalysisPlayground: wasm
Diagram source
flowchart LR
  vscode["VS Code: extension.ts, vscode-languageclient"] -->|"JSON-RPC over stdio"| loop["tempest lsp: serve"]
  loop --> docs["Open documents"]
  docs --> sources["Sources: memory layer, then disk, std built in"]
  sources --> unit["The library around a file"]
  unit --> settle["Settle"]
  settle --> analysis["Analysis"]
  analysis -->|"diagnostics, answers"| loop
  playground["Playground: wasm"] --> analysis

One loop, no async#

The server is one plain loop, serve, in the temper-lsp crate, which tempest lsp runs. A thread reads messages, each a Content-Length header and JSON, and hands them over a channel; the loop waits for the next message or a timer, whichever comes first. Messages are serde_json values, and their params and results lsp-types' structs; no async runtime. Only the native tempest uses the crate, so the wasm build, which answers the playground itself, doesn't carry it or those crates. What this costs (no cancellation, one request at a time) and the alternatives: one synchronous loop, in detail.

A panic, a bug in tempest, doesn't end the server: each request and each analysis is caught, the request answered with an error and the analysis's document given an "internal error" diagnostic, and the server goes on (in detail).

What gets analyzed#

What makes a unit stale, and the costs of settling it whole each time: units and staying current and the whole library settled again, in detail.

The queries#

Each is a method of Analysis, shared by the server and the playground:

How a query finds what's at a position: temper-analysis, in detail.

The VS Code extension#

Why each part of the extension is built as it is: the VS Code extension, in detail.

Where in the code#

In detail: The language server and editors in detail: each decision with its alternatives and Kotlin Temper's way, the main types, the tests, and known weaknesses.