PluginBench
Skill
Pass
Audit score 90

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-graph
Claude Code
Cursor
Windsurf
Cline

How to use rust-call-graph

  1. 1.Use `/rust-call-graph <function_name>` to show both callers and callees
  2. 2.Add `--direction in` to see only who calls the function
  3. 3.Add `--direction out` to see only what the function calls
  4. 4.Add `--depth N` to control traversal depth (default 3)
  5. 5.Review the ASCII tree output and analysis insights for complexity and potential issues

Use cases

Good for
  • 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
Who it's for
  • Rust developers refactoring or optimizing code
  • Code reviewers understanding function relationships
  • Developers onboarding to unfamiliar codebases
  • Performance engineers identifying bottlenecks

rust-call-graph FAQ

What's the difference between incoming and outgoing calls?

Incoming calls show functions that call your target (callers). Outgoing calls show functions your target calls (callees). Use `--direction in`, `out`, or `both`.

How deep should I set the depth parameter?

Default depth is 3 levels. Use higher values (5+) for deep execution path analysis, lower values (1-2) for quick overviews of direct relationships.

Can I export the call graph to documentation?

Yes, the skill can generate Mermaid diagram syntax for embedding in markdown docs or tools that support Mermaid.

What if a function uses dynamic dispatch or trait objects?

Dynamic dispatch calls are marked as `[dynamic dispatch]` in the output since the exact target cannot be statically determined.

Does this work with all Rust projects?

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 SaysDirectionUse Case
"Who calls X?"incomingImpact analysis
"What does X call?"outgoingUnderstanding implementation
"Show call graph"bothFull picture
"Trace from main to X"outgoingExecution path

Visualization Options

StyleBest For
Tree (default)Simple hierarchies
Box diagramComplex relationships
Flat listMany connections
MermaidExport 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

WhenSee
Find definitionrust-code-navigator
Project structurerust-symbol-analyzer
Trait implementationsrust-trait-explorer
Safe refactoringrust-refactor-helper