rust-analyzer-cli
Compiler-accurate Rust codebase navigation powered by rust-analyzer LSP and an embedded HTTP daemon.
rust-analyzer-cli is dual-structured as both a CLI tool and a Rust Library (rust_analyzer_cli), enabling developers, automation tools, and Rust programs to perform fast, compiler-accurate symbol search, document outline extraction, definition lookup, and Rust semantic navigation.
Features
- 🚀 Background Daemon & Persistent LSP Session: Spawns
rust-analyzervia JSON-RPC stdio and serves an embedded Axum HTTP REST server (default port60094). - 🔍 Workspace Symbol Search: Search for structs, enums, functions, traits, and variables across the entire workspace.
- 📜 Document Outline: Extract hierarchical document symbol outlines for any
.rsfile. - 🎯 Go to Definition: Jump directly to exact symbol definitions by file, line, and column.
- 💬 Hover Documentation: Read Rust type information and
///documentation at a file position. - 📞 Semantic Navigation: Query symbol references and incoming/outgoing calls with explicit agent-oriented commands.
- 🧩 Rust Relations: Query implementation locations with the Rust-native
relations --mode implementationscommand. - 🤖 Automation Friendly: Supports human-readable CLI outputs and
--jsonstructured formatting.
Installation
Requirements
- Rust and Cargo
rust-analyzeravailable inPATH- The
rust-srcandrust-analyzerrustup components
rust-src is required for standard-library documentation and source lookup.
An IDE extension alone does not provide the rust-analyzer command used by
the daemon.
Install and Initialize
From the target project workspace:
rustup component add rust-src rust-analyzer
cargo install rust-analyzer-cli
rust-analyzer-cli init-skill --workspace .
For repository development, use cargo run -- ... instead of a stale binary.
For compiler diagnostics, use the official cargo check command directly.
As a Rust Library
Add rust_analyzer_cli to your project's Cargo.toml:
[]
= "0.7.0"
Common Usage
Start the daemon from the target workspace root before querying:
rust-analyzer-cli daemon --workspace .
rust-analyzer-cli status
Common queries include hover, definition, body, outline, symbol,
references, calls, and relations. For example:
rust-analyzer-cli hover --file src/main.rs --line 15 --col 10
rust-analyzer-cli definition --file src/main.rs --line 15 --col 10 --body
rust-analyzer-cli references --file src/main.rs --line 25 --col 8
rust-analyzer-cli calls --file src/main.rs --line 25 --col 8 --direction incoming
rust-analyzer-cli calls --file src/main.rs --line 25 --col 8 --direction outgoing --depth 2
rust-analyzer-cli relations --file src/main.rs --line 25 --col 8 --mode implementations
Input paths are relative to the workspace used to start the daemon. Line and
column numbers are 1-based; columns count UTF-16 code units to match LSP.
Use --json for machine-readable output. For exact options, defaults,
coordinate rules, daemon requirements, and examples, use:
rust-analyzer-cli --help
rust-analyzer-cli <command> --help
Using as a Rust Library
You can embed the HTTP server or interact with data types directly in your Rust applications:
use start_daemon_server;
use *;
use PathBuf;
async
Project Skill
The navigation skill definition is included at .agents/skills/rust-codebase-navigation/SKILL.md. The init-skill command copies it into any project workspace.
For a project that already has this repository checked out, initialize the skill with Cargo during development:
cargo run -- init-skill --workspace .
For a globally installed binary, use rust-analyzer-cli init-skill --workspace . as shown above.
License
Dual-licensed under MIT or Apache-2.0.