LSP Support
How the Mist Language Server bridges editor requests through rust-analyzer.
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
- Editor sends Mist file edits to
mist-analyzervia LSP mist-analyzertranspiles Mist to Rust- The transpiled Rust is forwarded to the headless
rust-analyzerprocess - For goto-definition, hover, and completion, a unique marker token is injected at the cursor position
- The transpiled output with the marker is sent to
rust-analyzer - The marker position is located in the response
- 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 <name>;when new.mistfiles are created - File watching — Monitors
**/*.mistfor new files
Diagnostic Remapping
When a transpilation error occurs in the mist-analyzer:
- Parse errors are converted to
Diagnosticwith Mist source positions - Semantic errors (uninitialized class fields) use the stored line/column
- Rust compiler errors are remapped via the
Mappingsystem back to Mist positions