Rust Analyzer LSP
Verified@bowen31337
npx machina-cli add skill @bowen31337/rust-analyzer-lsp --openclawrust-analyzer LSP
Rust language server integration providing comprehensive code intelligence through rust-analyzer.
Capabilities
- Code intelligence: Autocomplete, go-to-definition, find references
- Error detection: Real-time diagnostics for compilation errors
- Refactoring: Rename symbols, extract function/variable
- Analysis: Macro expansion, type hints, inlay hints
- Supported extensions:
.rs
Installation
Via rustup (recommended)
rustup component add rust-analyzer
Via Homebrew (macOS)
brew install rust-analyzer
Via package manager (Linux)
# Ubuntu/Debian
sudo apt install rust-analyzer
# Arch Linux
sudo pacman -S rust-analyzer
Manual download
Download pre-built binaries from the releases page.
Verify installation:
rust-analyzer --version
Usage
The language server runs automatically in LSP-compatible editors. For manual operations:
Format code
cargo fmt
Run linter
cargo clippy
Build and test
cargo build
cargo test
Check without building
cargo check
Configuration
Create .rust-analyzer.json in project root:
{
"checkOnSave": {
"command": "clippy"
},
"inlayHints": {
"typeHints": true,
"parameterHints": true
}
}
Integration Pattern
When editing Rust code:
- rust-analyzer provides real-time diagnostics
- Run
cargo fmtto format code - Use
cargo clippyfor linting - Run
cargo testbefore committing
Common Cargo Commands
cargo new <name>- Create new projectcargo build- Compile projectcargo run- Build and runcargo test- Run testscargo check- Fast compile checkcargo clippy- Run lintercargo fmt- Format codecargo doc --open- Generate and open docs
More Information
Overview
Rust Analyzer LSP provides comprehensive code intelligence for Rust by leveraging rust-analyzer. It enables autocomplete, go-to-definition, find references, real-time error diagnostics, and refactoring support within LSP enabled editors, improving Rust development productivity.
How This Skill Works
The rust-analyzer LSP server runs in supported editors and analyzes Rust projects to expose features via the Language Server Protocol. It reads .rs sources and cargo project metadata to provide real-time diagnostics, code actions, macro insights, type hints, and inlay hints, plus refactoring tools like symbol rename or function extraction.
When to Use It
- When editing Rust code in an LSP compatible editor for .rs files and need autocomplete, go-to-definition, or find references
- During coding to get real-time error diagnostics and catch compilation errors early
- When performing refactoring tasks such as renaming symbols or extracting functions
- When trying to understand complex Rust patterns via macro expansion, type hints, and inlay hints
- When configuring a Rust project and maintaining code quality with formatting and linting using cargo commands
Quick Start
- Step 1: Install rust-analyzer via rustup component add rust-analyzer, Homebrew, or your Linux package manager
- Step 2: Enable LSP in your editor and connect to rust-analyzer, then open a Rust project
- Step 3: Create a .rust-analyzer.json configuration with checkOnSave and inlayHints, then use cargo fmt and cargo clippy as part of your workflow
Best Practices
- Keep rust-analyzer installed via rustup, Homebrew, or your distro package manager to stay up to date
- Enable inlay hints and type hints in .rust-analyzer.json to improve code readability
- Rely on real-time diagnostics to fix errors as you type before building
- Use go-to-definition and find references to safely navigate and understand code relationships
- Run cargo fmt and cargo clippy regularly, then cargo test to validate changes before committing
Example Use Cases
- Autocomplete and go-to-definition while implementing a function across multiple modules
- Refactor by renaming a symbol and seeing all references update automatically
- Inspect macro-expanded code to understand generated statements in a macro-heavy crate
- Inlay hints reveal parameter and type information in complex generic code
- Format and lint with cargo fmt and cargo clippy before running cargo test