--- title: LSP Support description: How the Mist Language Server bridges editor requests through rust-analyzer. icon: Server --- The Mist Language Server Protocol implementation runs a headless `rust-analyzer` instance and bridges Mist editor requests to Rust positions. ### Architecture ``` Editor (LSP client) │ ▼ ┌─────────────────────┐ │ mist-analyzer │ │ (Rust + Mist) │ └─────────────────────┘ │ ▲ │ JSON-RPC │ ▼ │ ┌─────────────────────┐ │ rust-analyzer │ │ (headless child) │ └─────────────────────┘ ``` ### Flow 1. Editor sends Mist file edits to `mist-analyzer` via LSP 2. `mist-analyzer` transpiles Mist to Rust 3. The transpiled Rust is forwarded to the headless `rust-analyzer` process 4. For goto-definition, hover, and completion, a unique marker token is injected at the cursor position 5. The transpiled output with the marker is sent to `rust-analyzer` 6. The marker position is located in the response 7. Results are mapped back to Mist positions using the `rev_mapper` ### Key Features - **Full document sync** — Open, change, save, close - **Go to definition** — Maps through transpiled Rust positions - **Completions** — Supports trigger characters `:`, `.`, `'`, `(` - **Hover** — Type information and docs - **Diagnostics** — Real-time errors from transpilation failures and Rust compilation - **Formatting** — Document formatting support - **Auto-import** — Automatically inserts `pub module ;` when new `.mist` files are created - **File watching** — Monitors `**/*.mist` for new files ### Diagnostic Remapping When a transpilation error occurs in the `mist-analyzer`: 1. Parse errors are converted to `Diagnostic` with Mist source positions 2. Semantic errors (uninitialized class fields) use the stored line/column 3. Rust compiler errors are remapped via the `Mapping` system back to Mist positions