How rust-lang/rust-analyzer works
rust-analyzer is a Rust language server that turns editor requests into semantic IDE results and code edits. Its principal workflow spans project loading, parsing, macro expansion, semantic analysis, and IDE features; the VS Code extension is one editor client. The README documents completion, navigation, refactoring, formatting, and diagnostics, but the excerpts do not show most server-side dispatch or analysis calls. Accordingly, several internal links are marked unverified rather than asserted as observed control flow.
Main entry points: main_loop.rs Request loop · src/lib.rs IDE API · src/lib.rs HIR definitions · client.ts LSP client
Components 24
Editor client
- VS Code extension
editors/code/src/main.ts - LSP client
editors/code/src/client.ts
Language server
- Server binary
crates/rust-analyzer/src/bin/main.rs - Server session
crates/rust-analyzer/src/session.rs - Request loop
crates/rust-analyzer/src/main_loop.rs - Workspace loading
crates/load-cargo/src/lib.rs - Cargo project model
crates/project-model/src/workspace.rs - Virtual files
crates/vfs/src/lib.rs
Rust analysis
- Rust parser
crates/parser/src/parser.rs - Syntax trees
crates/syntax/src/lib.rs - Incremental database
crates/base-db/src/lib.rs - HIR definitions
crates/hir-def/src/lib.rs - Macro expansion
crates/hir-expand/src/lib.rs - Procedural macros
crates/proc-macro-srv/src/lib.rs - Type analysis
crates/hir-ty/src/lib.rs - HIR API
crates/hir/src/lib.rs
IDE features
- IDE API
crates/ide/src/lib.rs - Code completion
crates/ide-completion/src/lib.rs - Refactorings
crates/ide-assists/src/lib.rs - Diagnostics
crates/ide-diagnostics/src/lib.rs - IDE database tools
crates/ide-db/src/lib.rs
Other components
- Editor
- rustc and Clippy
- rustfmt
Connections 24
- Editor → VS Code extension: uses extension
README.md - Editor → LSP client: uses LSP
README.md - VS Code extension → LSP client: starts client
- LSP client → Server binary: sends requests
- Server binary → Server session: starts session
- Server session → Request loop: runs loop
crates/rust-analyzer/src/session.rs - Request loop → Workspace loading: loads workspace
- Workspace loading → Cargo project model: loads Cargo model
- Request loop → Virtual files: accesses files
- Virtual files → Rust parser: provides source
- Rust parser → Syntax trees: produces syntax
- Syntax trees → Incremental database: feeds analysis
- Incremental database → HIR definitions: supports definitions
- HIR definitions → Macro expansion: expands macros
- Macro expansion → Procedural macros: invokes macros
- HIR definitions → Type analysis: supports typing
- Type analysis → HIR API: provides semantics
- Request loop → IDE API: dispatches features
- IDE API → Code completion: offers completion
- IDE API → Refactorings: offers refactoring
- IDE API → Diagnostics: provides diagnostics
- IDE API → IDE database tools: uses IDE services
- Request loop → rustc and Clippy: requests diagnostics
README.md - Request loop → rustfmt: requests formatting
README.md