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, call hierarchy analysis, and compilation checks.
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. - 📞 Call Hierarchy & References: Query incoming/outgoing call chains and symbol reference locations.
- 🧬 Type Hierarchy: Traverse supertypes and subtypes.
- 🛠 Cargo Check Integration: Run
cargo checkand parse structured compiler diagnostics. - 🤖 Automation Friendly: Supports human-readable CLI outputs and
--jsonstructured formatting.
Installation
Install and Initialize the Project Skill
Install the published crate, then run the initialization command from the target project workspace:
cargo install rust-analyzer-cli
rust-analyzer-cli init-skill --workspace .
The second command writes the skill to
.agents/skills/rust-codebase-navigation/SKILL.md. Tools can then read this
file and use the documented commands to inspect the Rust project.
Requirements:
- Rust and Cargo must be installed and available in
PATH. rust-analyzermust be installed and available inPATH.
To write the skill to another project-relative path:
rust-analyzer-cli init-skill --workspace . --dir .agents/skills/rust-codebase-navigation/SKILL.md
As a CLI Tool
Prerequisite: Ensure rust-analyzer is installed and available in your system PATH.
As a Rust Library
Add rust_analyzer_cli to your project's Cargo.toml:
[]
= "0.4.1"
Usage Guide
1. Start the Background Daemon
Before running queries, start the daemon from your workspace root:
To check daemon & LSP indexing status:
To refresh/restart the rust-analyzer session:
Query commands require the daemon to be running. File paths are interpreted
from the workspace used to start the daemon, and line/column positions are
1-based. In --json mode stdout contains only machine-readable JSON. A valid
query with no result returns an empty array or null; this is not an error.
2. Core Commands
Search Workspace Symbols
# Example:
Extract File Outline
# Example:
Provide exactly one of --file and --file-list. With --body, source output
is limited to 100 lines by default; use --max-lines 0 for unlimited output.
When --json --output <path> is used, the outline JSON is written to the file
and stdout contains a JSON success summary with the output path.
Go to Definition
# Example:
Use 1-based line and column numbers. The optional body output uses the same
100-line default; the body command reports truncation in human-readable mode.
Inspect Source Body
# Example:
The default body limit is 100 lines. A truncation message includes both the
displayed and total line counts; --max-lines 0 disables the limit.
Hover Documentation
# Example:
References & Call Hierarchy
# Example:
--depth defaults to 1 and controls call-hierarchy traversal. The
references mode uses the direct LSP reference query, so depth does not add
additional traversal in that mode.
Type Hierarchy
--depth defaults to 1 and controls the number of supertype or subtype levels
returned. Results are de-duplicated when a hierarchy contains cycles or shared
parents.
Cargo Check Verification
When compilation fails, the command includes Cargo diagnostics and, when no structured compiler diagnostic is available, Cargo's stderr failure message.
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.