# rust-lang/rust-analyzer architecture

> Architecture diagram of the GitHub repository rust-lang/rust-analyzer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rust-lang/rust-analyzer
- Repository: https://github.com/rust-lang/rust-analyzer

## Overview

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: [`crates/rust-analyzer/src/main_loop.rs`](https://github.com/rust-lang/rust-analyzer/blob/master/crates/rust-analyzer/src/main_loop.rs) (Request loop), [`crates/ide/src/lib.rs`](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide/src/lib.rs) (IDE API), [`crates/hir-def/src/lib.rs`](https://github.com/rust-lang/rust-analyzer/blob/master/crates/hir-def/src/lib.rs) (HIR definitions), [`editors/code/src/client.ts`](https://github.com/rust-lang/rust-analyzer/blob/master/editors/code/src/client.ts) (LSP client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Editor client"]
  node_vscode["VS Code extension<br/>[main.ts]"]
  node_lsp_client["LSP client<br/>[client.ts]"]
end

subgraph group_server["Language server"]
  node_server_bin["Server binary<br/>[main.rs]"]
  node_session["Server session<br/>[session.rs]"]
  node_main_loop["Request loop<br/>[main_loop.rs]"]
  node_workspace["Workspace loading<br/>[lib.rs]"]
  node_project_model["Cargo project model<br/>[workspace.rs]"]
  node_vfs[("Virtual files<br/>[lib.rs]")]
end

subgraph group_analysis["Rust analysis"]
  node_parser["Rust parser<br/>[parser.rs]"]
  node_syntax["Syntax trees<br/>[lib.rs]"]
  node_base_db[("Incremental database<br/>[lib.rs]")]
  node_hir_def["HIR definitions<br/>[lib.rs]"]
  node_macro_expansion["Macro expansion<br/>[lib.rs]"]
  node_proc_macro["Procedural macros<br/>[lib.rs]"]
  node_hir_ty["Type analysis<br/>[lib.rs]"]
  node_hir["HIR API<br/>[lib.rs]"]
end

subgraph group_ide["IDE features"]
  node_ide_api["IDE API<br/>[lib.rs]"]
  node_completion["Code completion<br/>[lib.rs]"]
  node_assists["Refactorings<br/>[lib.rs]"]
  node_diagnostics["Diagnostics<br/>[lib.rs]"]
  node_ide_db["IDE database tools<br/>[lib.rs]"]
end

node_editor(("Editor"))
node_rustc["rustc and Clippy"]
node_rustfmt["rustfmt"]

node_editor -->|"uses extension"| node_vscode
node_editor -->|"uses LSP"| node_lsp_client
node_vscode -.->|"starts client"| node_lsp_client
node_lsp_client -.->|"sends requests"| node_server_bin
node_server_bin -.->|"starts session"| node_session
node_session -->|"runs loop"| node_main_loop
node_main_loop -.->|"loads workspace"| node_workspace
node_workspace -.->|"loads Cargo model"| node_project_model
node_main_loop -.->|"accesses files"| node_vfs
node_vfs -.->|"provides source"| node_parser
node_parser -.->|"produces syntax"| node_syntax
node_syntax -.->|"feeds analysis"| node_base_db
node_base_db -.->|"supports definitions"| node_hir_def
node_hir_def -.->|"expands macros"| node_macro_expansion
node_macro_expansion -.->|"invokes macros"| node_proc_macro
node_hir_def -.->|"supports typing"| node_hir_ty
node_hir_ty -.->|"provides semantics"| node_hir
node_main_loop -.->|"dispatches features"| node_ide_api
node_ide_api -.->|"offers completion"| node_completion
node_ide_api -.->|"offers refactoring"| node_assists
node_ide_api -.->|"provides diagnostics"| node_diagnostics
node_ide_api -.->|"uses IDE services"| node_ide_db
node_main_loop -.->|"requests diagnostics"| node_rustc
node_main_loop -.->|"requests formatting"| node_rustfmt

click node_vscode "https://github.com/rust-lang/rust-analyzer/blob/master/editors/code/src/main.ts"
click node_lsp_client "https://github.com/rust-lang/rust-analyzer/blob/master/editors/code/src/client.ts"
click node_server_bin "https://github.com/rust-lang/rust-analyzer/blob/master/crates/rust-analyzer/src/bin/main.rs"
click node_session "https://github.com/rust-lang/rust-analyzer/blob/master/crates/rust-analyzer/src/session.rs"
click node_main_loop "https://github.com/rust-lang/rust-analyzer/blob/master/crates/rust-analyzer/src/main_loop.rs"
click node_workspace "https://github.com/rust-lang/rust-analyzer/blob/master/crates/load-cargo/src/lib.rs"
click node_project_model "https://github.com/rust-lang/rust-analyzer/blob/master/crates/project-model/src/workspace.rs"
click node_vfs "https://github.com/rust-lang/rust-analyzer/blob/master/crates/vfs/src/lib.rs"
click node_parser "https://github.com/rust-lang/rust-analyzer/blob/master/crates/parser/src/parser.rs"
click node_syntax "https://github.com/rust-lang/rust-analyzer/blob/master/crates/syntax/src/lib.rs"
click node_base_db "https://github.com/rust-lang/rust-analyzer/blob/master/crates/base-db/src/lib.rs"
click node_hir_def "https://github.com/rust-lang/rust-analyzer/blob/master/crates/hir-def/src/lib.rs"
click node_macro_expansion "https://github.com/rust-lang/rust-analyzer/blob/master/crates/hir-expand/src/lib.rs"
click node_proc_macro "https://github.com/rust-lang/rust-analyzer/blob/master/crates/proc-macro-srv/src/lib.rs"
click node_hir_ty "https://github.com/rust-lang/rust-analyzer/blob/master/crates/hir-ty/src/lib.rs"
click node_hir "https://github.com/rust-lang/rust-analyzer/blob/master/crates/hir/src/lib.rs"
click node_ide_api "https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide/src/lib.rs"
click node_completion "https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-completion/src/lib.rs"
click node_assists "https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/lib.rs"
click node_diagnostics "https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/lib.rs"
click node_ide_db "https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-db/src/lib.rs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_vscode,node_lsp_client toneBlue
class node_server_bin,node_session,node_main_loop,node_workspace,node_project_model,node_vfs toneAmber
class node_parser,node_syntax,node_base_db,node_hir_def,node_macro_expansion,node_proc_macro,node_hir_ty,node_hir toneMint
class node_ide_api,node_completion,node_assists,node_diagnostics,node_ide_db toneRose
class node_editor,node_rustc,node_rustfmt toneIndigo
```

## Components

### Editor client

- [VS Code extension](https://github.com/rust-lang/rust-analyzer/blob/master/editors/code/src/main.ts): `editors/code/src/main.ts`
- [LSP client](https://github.com/rust-lang/rust-analyzer/blob/master/editors/code/src/client.ts): `editors/code/src/client.ts`

### Language server

- [Server binary](https://github.com/rust-lang/rust-analyzer/blob/master/crates/rust-analyzer/src/bin/main.rs): `crates/rust-analyzer/src/bin/main.rs`
- [Server session](https://github.com/rust-lang/rust-analyzer/blob/master/crates/rust-analyzer/src/session.rs): `crates/rust-analyzer/src/session.rs`
- [Request loop](https://github.com/rust-lang/rust-analyzer/blob/master/crates/rust-analyzer/src/main_loop.rs): `crates/rust-analyzer/src/main_loop.rs`
- [Workspace loading](https://github.com/rust-lang/rust-analyzer/blob/master/crates/load-cargo/src/lib.rs): `crates/load-cargo/src/lib.rs`
- [Cargo project model](https://github.com/rust-lang/rust-analyzer/blob/master/crates/project-model/src/workspace.rs): `crates/project-model/src/workspace.rs`
- [Virtual files](https://github.com/rust-lang/rust-analyzer/blob/master/crates/vfs/src/lib.rs): `crates/vfs/src/lib.rs`

### Rust analysis

- [Rust parser](https://github.com/rust-lang/rust-analyzer/blob/master/crates/parser/src/parser.rs): `crates/parser/src/parser.rs`
- [Syntax trees](https://github.com/rust-lang/rust-analyzer/blob/master/crates/syntax/src/lib.rs): `crates/syntax/src/lib.rs`
- [Incremental database](https://github.com/rust-lang/rust-analyzer/blob/master/crates/base-db/src/lib.rs): `crates/base-db/src/lib.rs`
- [HIR definitions](https://github.com/rust-lang/rust-analyzer/blob/master/crates/hir-def/src/lib.rs): `crates/hir-def/src/lib.rs`
- [Macro expansion](https://github.com/rust-lang/rust-analyzer/blob/master/crates/hir-expand/src/lib.rs): `crates/hir-expand/src/lib.rs`
- [Procedural macros](https://github.com/rust-lang/rust-analyzer/blob/master/crates/proc-macro-srv/src/lib.rs): `crates/proc-macro-srv/src/lib.rs`
- [Type analysis](https://github.com/rust-lang/rust-analyzer/blob/master/crates/hir-ty/src/lib.rs): `crates/hir-ty/src/lib.rs`
- [HIR API](https://github.com/rust-lang/rust-analyzer/blob/master/crates/hir/src/lib.rs): `crates/hir/src/lib.rs`

### IDE features

- [IDE API](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide/src/lib.rs): `crates/ide/src/lib.rs`
- [Code completion](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-completion/src/lib.rs): `crates/ide-completion/src/lib.rs`
- [Refactorings](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/lib.rs): `crates/ide-assists/src/lib.rs`
- [Diagnostics](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/lib.rs): `crates/ide-diagnostics/src/lib.rs`
- [IDE database tools](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-db/src/lib.rs): `crates/ide-db/src/lib.rs`

### Other components

- **Editor**
- **rustc and Clippy**
- **rustfmt**

## Connections

- Editor → VS Code extension: uses extension (evidence: `README.md`)
- Editor → LSP client: uses LSP (evidence: `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 (evidence: `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 (evidence: `README.md`)
- Request loop → rustfmt: requests formatting (evidence: `README.md`)
