Why building a Rust LSP is hard
2 days ago
- LSPs need to balance providing useful answers quickly with full indexing, embracing partial information.
- Indexing in Rust LSPs involves layers: parsing, item tree building, defmaps, macro expansion, and body analysis.
- Rust-analyzer uses salsa, an incremental database, while Rust Glancer uses eager indexing with a filesystem-offloaded state.
- LSPs must handle incorrect/incomplete code, using CST and creative parsing to suggest fixes and completions.
- Cursor analysis differs: rust-analyzer uses syntax-tree matching, Rust Glancer uses span-based with full semantic analysis.
- Completions require context-aware guessing, like after dots or '::', considering type, scope, and user intent.
- LSP architecture choices vary: rust-analyzer is eager, Rust Glancer is lazy and process-isolated per workspace.
- Working with LSP protocol involves UTF-16, line/column conversions, and handling user intent ambiguities like multi-workspace folders.
- Indexing is query-driven, not just compilation, and must process incremental updates efficiently.
- Rust LSPs must integrate with external tools (cargo, rustdoc) to provide diagnostics, tests, and fluent user experience.