rust-call-graph
actionbook/rust-skills
Visualize Rust function call graphs and trace caller/callee relationships using LSP.
What is rust-call-graph?
Generates ASCII call graphs showing which functions call a target function and which functions it calls. Use this to understand code flow, trace execution paths, identify hot paths, and analyze function dependencies in Rust projects.
- Trace incoming calls (who calls a function) with configurable depth
- Trace outgoing calls (what a function calls) with configurable depth
- Generate bidirectional call graphs showing both callers and callees
- Display ASCII tree and box-diagram visualizations of call relationships
- Provide analysis insights including entry points, leaf functions, and complexity metrics
- Support recursive expansion up to N levels deep
How to install rust-call-graph
npx skills add https://github.com/actionbook/rust-skills --skill rust-call-graphHow to use rust-call-graph
- 1.Use `/rust-call-graph <function_name>` to show both callers and callees
- 2.Add `--direction in` to see only who calls the function
- 3.Add `--direction out` to see only what the function calls
- 4.Add `--depth N` to control traversal depth (default 3)
- 5.Review the ASCII tree output and analysis insights for complexity and potential issues
Use cases
- Understand execution flow by tracing from main() to a target function
- Identify all callers of a function to assess impact before refactoring
- Analyze function dependencies and detect high fan-out (functions with many callees)
- Trace hot paths in performance-critical code sections
- Explore implementation details by seeing what a function calls
- Rust developers refactoring or optimizing code
- Code reviewers understanding function relationships
- Developers onboarding to unfamiliar codebases
- Performance engineers identifying bottlenecks
rust-call-graph FAQ
Incoming calls show functions that call your target (callers). Outgoing calls show functions your target calls (callees). Use `--direction in`, `out`, or `both`.
Default depth is 3 levels. Use higher values (5+) for deep execution path analysis, lower values (1-2) for quick overviews of direct relationships.
Yes, the skill can generate Mermaid diagram syntax for embedding in markdown docs or tools that support Mermaid.
Dynamic dispatch calls are marked as `[dynamic dispatch]` in the output since the exact target cannot be statically determined.
This requires an LSP server (rust-analyzer) to be running. It works best with projects that have proper Cargo.toml configuration.
Full instructions (SKILL.md)
Source of truth, from actionbook/rust-skills.
name: rust-call-graph description: "Visualize Rust function call graphs using LSP. Triggers on: /call-graph, call hierarchy, who calls, what calls, 调用图, 调用关系, 谁调用了, 调用了谁" argument-hint: "<function_name> [--depth N] [--direction in|out|both]" allowed-tools: ["LSP", "Read", "Glob"]
Rust Call Graph
Visualize function call relationships using LSP call hierarchy.
Usage
/rust-call-graph <function_name> [--depth N] [--direction in|out|both]
Options:
--depth N: How many levels to traverse (default: 3)--direction:in(callers),out(callees),both
Examples:
/rust-call-graph process_request- Show both callers and callees/rust-call-graph handle_error --direction in- Show only callers/rust-call-graph main --direction out --depth 5- Deep callee analysis
LSP Operations
1. Prepare Call Hierarchy
Get the call hierarchy item for a function.
LSP(
operation: "prepareCallHierarchy",
filePath: "src/handler.rs",
line: 45,
character: 8
)
2. Incoming Calls (Who calls this?)
LSP(
operation: "incomingCalls",
filePath: "src/handler.rs",
line: 45,
character: 8
)
3. Outgoing Calls (What does this call?)
LSP(
operation: "outgoingCalls",
filePath: "src/handler.rs",
line: 45,
character: 8
)
Workflow
User: "Show call graph for process_request"
│
▼
[1] Find function location
LSP(workspaceSymbol) or Grep
│
▼
[2] Prepare call hierarchy
LSP(prepareCallHierarchy)
│
▼
[3] Get incoming calls (callers)
LSP(incomingCalls)
│
▼
[4] Get outgoing calls (callees)
LSP(outgoingCalls)
│
▼
[5] Recursively expand to depth N
│
▼
[6] Generate ASCII visualization
Output Format
Incoming Calls (Who calls this?)
## Callers of `process_request`
main
└── run_server
└── handle_connection
└── process_request ◄── YOU ARE HERE
Outgoing Calls (What does this call?)
## Callees of `process_request`
process_request ◄── YOU ARE HERE
├── parse_headers
│ └── validate_header
├── authenticate
│ ├── check_token
│ └── load_user
├── execute_handler
│ └── [dynamic dispatch]
└── send_response
└── serialize_body
Bidirectional (Both)
## Call Graph for `process_request`
┌─────────────────┐
│ main │
└────────┬────────┘
│
┌────────▼────────┐
│ run_server │
└────────┬────────┘
│
┌────────▼────────┐
│handle_connection│
└────────┬────────┘
│
┌────────────────────┼────────────────────┐
│ │ │
┌───────▼───────┐ ┌───────▼───────┐ ┌───────▼───────┐
│ parse_headers │ │ authenticate │ │send_response │
└───────────────┘ └───────┬───────┘ └───────────────┘
│
┌───────┴───────┐
│ │
┌──────▼──────┐ ┌──────▼──────┐
│ check_token │ │ load_user │
└─────────────┘ └─────────────┘
Analysis Insights
After generating the call graph, provide insights:
## Analysis
**Entry Points:** main, test_process_request
**Leaf Functions:** validate_header, serialize_body
**Hot Path:** main → run_server → handle_connection → process_request
**Complexity:** 12 functions, 3 levels deep
**Potential Issues:**
- `authenticate` has high fan-out (4 callees)
- `process_request` is called from 3 places (consider if this is intentional)
Common Patterns
| User Says | Direction | Use Case |
|---|---|---|
| "Who calls X?" | incoming | Impact analysis |
| "What does X call?" | outgoing | Understanding implementation |
| "Show call graph" | both | Full picture |
| "Trace from main to X" | outgoing | Execution path |
Visualization Options
| Style | Best For |
|---|---|
| Tree (default) | Simple hierarchies |
| Box diagram | Complex relationships |
| Flat list | Many connections |
| Mermaid | Export to docs |
Mermaid Export
graph TD
main --> run_server
run_server --> handle_connection
handle_connection --> process_request
process_request --> parse_headers
process_request --> authenticate
process_request --> send_response
Related Skills
| When | See |
|---|---|
| Find definition | rust-code-navigator |
| Project structure | rust-symbol-analyzer |
| Trait implementations | rust-trait-explorer |
| Safe refactoring | rust-refactor-helper |
Related skills
More from actionbook/rust-skills and the wider catalog.

rust-code-navigator
Navigate Rust code with LSP: go to definition, find references, and explore symbols efficiently.

rust-daily
Fetch Rust community news and updates filtered by time range (daily, weekly, or monthly).

rust-deps-visualizer
Visualize Rust project dependencies as ASCII art trees with optional feature flags.

rust-learner
Fetch Rust versions, crate info, and API documentation from official sources.

rust-refactor-helper
Safe Rust refactoring with LSP-powered impact analysis and dry-run preview.

rust-router
Router skill for all Rust questions—directs to specialized language, design, and domain skills.