Editor & rust-analyzer Setup
Configure VS Code (or Cursor) with rust-analyzer for fast navigation, macro expansion, and test runs on Solana/Anchor programs.
Search across all documentation pages
Configure VS Code (or Cursor) with rust-analyzer for fast navigation, macro expansion, and test runs on Solana/Anchor programs.
Quick-reference recipe card - copy-paste ready.
rustup component add rust-analyzer
code --install-extension rust-lang.rust-analyzer.vscode/settings.json essentials:
{
"rust-analyzer.cargo.extraEnv": {},
"rust-analyzer.check.command": "clippy",
"editor.formatOnSave": true
}When to reach for this:
#[program] modules.anchor build compile cycles.cargo test for off-chain parsers next to programs.# Pin Rust at repo root
cat > rust-toolchain.toml <<'EOF'
[toolchain]
channel = "1.91.1"
components = ["rustfmt", "clippy", "rust-analyzer"]
EOF
rustup show active-toolchain
# Open Anchor workspace
cd my_anchor_program
code .
# In editor: open programs/my_program/src/lib.rs
# rust-analyzer should index after "cargo metadata" completesWorkspace settings.json:
{
"rust-analyzer.linkedProjects": ["programs/my_program/Cargo.toml"],
"rust-analyzer.cargo.buildScripts.enable": true,
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer"
}
}What this demonstrates:
rust-toolchain.toml pins 1.91.1 for analyzer and CLI parity.linkedProjects helps monorepos where root may not be a Rust crate.buildScripts.enable resolves anchor-syn build script generated code.cargo check on save for fast feedback.#[program], #[account]) require build script output.tests/ or clients/ can be separate workspace members.rustfmt consistent with cargo fmt CI.| Extension | Purpose |
|---|---|
| rust-analyzer | LSP for Rust |
| Even Better TOML | Anchor.toml editing |
| Error Lens | Inline diagnostics |
| crates | Cargo.toml version hints |
# Restart analyzer cache when macros break
rm -rf target/debug/incremental
cargo clean && anchor buildrust-toolchain.toml; reload window.buildScripts; run anchor build once.programs/* subfolder alone. Fix: open repo root with Anchor.toml.target/ in file watcher settings.| Alternative | Use When | Don't Use When |
|---|---|---|
| IntelliJ Rust | JetBrains shop | VS Code/Cursor standard |
vim + rust-analyzer | Terminal-centric | Teaching new hires |
zed editor | Lightweight LSP | Anchor macro debugging immature |
CLI-only cargo check | CI minimalism | Daily feature development |
Run anchor build once so proc-macro artifacts generate; ensure linkedProjects points at program crate.
No - match stable 1.91.1 pin for Solana program compatibility.
Enable editor.formatOnSave with rust-analyzer as default Rust formatter.
Use integrated terminal for anchor test; analyzer focuses on cargo check speed.
Use ESLint/TypeScript language service in app/ - separate from rust-analyzer.
Exclude target/, limit workspace members, disable unused features in Cargo.toml.
Same rust-analyzer extension and settings apply.
Use msg! logs and LiteSVM tests; native step-debugging is limited vs off-chain Rust.
Optional - check.command: clippy is stricter but slower than check.
Commit .vscode/settings.json and rust-toolchain.toml for team consistency.
Stack versions: This page was written for Agave 4.1.1, Solana CLI 3.0.10, Anchor 0.32.1, anchor-lang 0.32.1, Rust 1.91.1, @solana/kit 7.0.0, Surfpool 0.12.0, and LiteSVM 0.6.x.
Reviewed by Chris St. John·Last updated Jul 16, 2026