rust-call-graph

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Rust Call Graph

Rust函数调用图

Visualize function call relationships using LSP call hierarchy.
使用LSP调用层级可视化函数调用关系。

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
/rust-call-graph <function_name> [--depth N] [--direction in|out|both]
选项:
  • --depth N
    :遍历的层级数(默认值:3)
  • --direction
    in
    (调用方)、
    out
    (被调用方)、
    both
    (双向)
示例:
  • /rust-call-graph process_request
    - 显示调用方和被调用方
  • /rust-call-graph handle_error --direction in
    - 仅显示调用方
  • /rust-call-graph main --direction out --depth 5
    - 深度被调用方分析

LSP Operations

LSP操作

1. Prepare Call Hierarchy

1. 准备调用层级

Get the call hierarchy item for a function.
LSP(
  operation: "prepareCallHierarchy",
  filePath: "src/handler.rs",
  line: 45,
  character: 8
)
获取函数的调用层级项。
LSP(
  operation: "prepareCallHierarchy",
  filePath: "src/handler.rs",
  line: 45,
  character: 8
)

2. Incoming Calls (Who calls this?)

2. 传入调用(谁调用了这个函数?)

LSP(
  operation: "incomingCalls",
  filePath: "src/handler.rs",
  line: 45,
  character: 8
)
LSP(
  operation: "incomingCalls",
  filePath: "src/handler.rs",
  line: 45,
  character: 8
)

3. Outgoing Calls (What does this call?)

3. 传出调用(这个函数调用了谁?)

LSP(
  operation: "outgoingCalls",
  filePath: "src/handler.rs",
  line: 45,
  character: 8
)
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
用户:"显示process_request的调用图"
[1] 查找函数位置
    LSP(workspaceSymbol) 或 Grep
[2] 准备调用层级
    LSP(prepareCallHierarchy)
[3] 获取传入调用(调用方)
    LSP(incomingCalls)
[4] 获取传出调用(被调用方)
    LSP(outgoingCalls)
[5] 递归扩展至N层
[6] 生成ASCII可视化图

Output Format

输出格式

Incoming Calls (Who calls this?)

传入调用(谁调用了这个函数?)

undefined
undefined

Callers of
process_request

Callers of
process_request

main └── run_server └── handle_connection └── process_request ◄── YOU ARE HERE
undefined
main └── run_server └── handle_connection └── process_request ◄── YOU ARE HERE
undefined

Outgoing Calls (What does this call?)

传出调用(这个函数调用了谁?)

undefined
undefined

Callees of
process_request

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
undefined
process_request ◄── YOU ARE HERE ├── parse_headers │ └── validate_header ├── authenticate │ ├── check_token │ └── load_user ├── execute_handler │ └── [dynamic dispatch] └── send_response └── serialize_body
undefined

Bidirectional (Both)

双向(Both)

undefined
undefined

Call Graph for
process_request

Call Graph for
process_request

┌─────────────────┐ │ main │ └────────┬────────┘ │ ┌────────▼────────┐ │ run_server │ └────────┬────────┘ │ ┌────────▼────────┐ │handle_connection│ └────────┬────────┘ │ ┌────────────────────┼────────────────────┐ │ │ │ ┌───────▼───────┐ ┌───────▼───────┐ ┌───────▼───────┐ │ parse_headers │ │ authenticate │ │send_response │ └───────────────┘ └───────┬───────┘ └───────────────┘ │ ┌───────┴───────┐ │ │ ┌──────▼──────┐ ┌──────▼──────┐ │ check_token │ │ load_user │ └─────────────┘ └─────────────┘
undefined
┌─────────────────┐ │ main │ └────────┬────────┘ │ ┌────────▼────────┐ │ run_server │ └────────┬────────┘ │ ┌────────▼────────┐ │handle_connection│ └────────┬────────┘ │ ┌────────────────────┼────────────────────┐ │ │ │ ┌───────▼───────┐ ┌───────▼───────┐ ┌───────▼───────┐ │ parse_headers │ │ authenticate │ │send_response │ └───────────────┘ └───────┬───────┘ └───────────────┘ │ ┌───────┴───────┐ │ │ ┌──────▼──────┐ ┌──────▼──────┐ │ check_token │ │ load_user │ └─────────────┘ └─────────────┘
undefined

Analysis Insights

分析洞察

After generating the call graph, provide insights:
undefined
生成调用图后,提供以下分析信息:
undefined

Analysis

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)
undefined
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)
undefined

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
用户提问方向使用场景
"Who calls X?"incoming影响分析
"What does X call?"outgoing实现逻辑理解
"Show call graph"both全局视图
"Trace from main to X"outgoing执行路径追踪

Visualization Options

可视化选项

StyleBest For
Tree (default)Simple hierarchies
Box diagramComplex relationships
Flat listMany connections
MermaidExport to docs
样式适用场景
树形(默认)简单层级结构
框图复杂关系
扁平列表大量连接
Mermaid导出至文档

Mermaid Export

Mermaid导出

mermaid
graph TD
    main --> run_server
    run_server --> handle_connection
    handle_connection --> process_request
    process_request --> parse_headers
    process_request --> authenticate
    process_request --> send_response
mermaid
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
场景参考技能
查找定义rust-code-navigator
项目结构rust-symbol-analyzer
Trait实现rust-trait-explorer
安全重构rust-refactor-helper