rust-call-graph
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRust 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:
- : How many levels to traverse (default: 3)
--depth N - :
--direction(callers),in(callees),outboth
Examples:
- - Show both callers and callees
/rust-call-graph process_request - - Show only callers
/rust-call-graph handle_error --direction in - - Deep callee analysis
/rust-call-graph main --direction out --depth 5
/rust-call-graph <function_name> [--depth N] [--direction in|out|both]选项:
- :遍历的层级数(默认值:3)
--depth N - :
--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?)
传入调用(谁调用了这个函数?)
undefinedundefinedCallers of process_request
process_requestCallers of process_request
process_requestmain
└── run_server
└── handle_connection
└── process_request ◄── YOU ARE HERE
undefinedmain
└── run_server
└── handle_connection
└── process_request ◄── YOU ARE HERE
undefinedOutgoing Calls (What does this call?)
传出调用(这个函数调用了谁?)
undefinedundefinedCallees of process_request
process_requestCallees of process_request
process_requestprocess_request ◄── YOU ARE HERE
├── parse_headers
│ └── validate_header
├── authenticate
│ ├── check_token
│ └── load_user
├── execute_handler
│ └── [dynamic dispatch]
└── send_response
└── serialize_body
undefinedprocess_request ◄── YOU ARE HERE
├── parse_headers
│ └── validate_header
├── authenticate
│ ├── check_token
│ └── load_user
├── execute_handler
│ └── [dynamic dispatch]
└── send_response
└── serialize_body
undefinedBidirectional (Both)
双向(Both)
undefinedundefinedCall Graph for process_request
process_requestCall Graph for process_request
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 │
└─────────────┘ └─────────────┘
undefinedAnalysis Insights
分析洞察
After generating the call graph, provide insights:
undefined生成调用图后,提供以下分析信息:
undefinedAnalysis
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:
- has high fan-out (4 callees)
authenticate - is called from 3 places (consider if this is intentional)
process_request
undefinedEntry 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:
- has high fan-out (4 callees)
authenticate - is called from 3 places (consider if this is intentional)
process_request
undefinedCommon 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 |
| 用户提问 | 方向 | 使用场景 |
|---|---|---|
| "Who calls X?" | incoming | 影响分析 |
| "What does X call?" | outgoing | 实现逻辑理解 |
| "Show call graph" | both | 全局视图 |
| "Trace from main to X" | outgoing | 执行路径追踪 |
Visualization Options
可视化选项
| Style | Best For |
|---|---|
| Tree (default) | Simple hierarchies |
| Box diagram | Complex relationships |
| Flat list | Many connections |
| Mermaid | Export 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_responsemermaid
graph TD
main --> run_server
run_server --> handle_connection
handle_connection --> process_request
process_request --> parse_headers
process_request --> authenticate
process_request --> send_responseRelated Skills
相关技能
| When | See |
|---|---|
| Find definition | rust-code-navigator |
| Project structure | rust-symbol-analyzer |
| Trait implementations | rust-trait-explorer |
| Safe refactoring | rust-refactor-helper |
| 场景 | 参考技能 |
|---|---|
| 查找定义 | rust-code-navigator |
| 项目结构 | rust-symbol-analyzer |
| Trait实现 | rust-trait-explorer |
| 安全重构 | rust-refactor-helper |