rust-call-graph について
LSP の呼び出し階層操作で Rust 関数間の関係を可視化するスキルです。方向と深さを指定し、呼び出し元や呼び出し先、両方を調べられます。
主な機能
- 01呼び出し元と呼び出し先の表示
- 02探索方向の指定
- 03グラフの深さの設定
- 04Mermaid 図として出力
活用シーン
- 01関数の呼び出し元を追跡
- 02関数が呼び出す関数を確認
- 03main から実行経路をたどる
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ actionbook/ rust-skills --skill rust-call-graphインストール後、Claude Code で/rust-call-graphを入力して読み込まれたか確認します。
詳細
Rust 呼び出しグラフ
LSP の呼び出し階層を使用して、関数の呼び出し関係を可視化します。
使い方
/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 操作
1. 呼び出し階層の準備
関数の呼び出し階層項目を取得します。
LSP(
operation: "prepareCallHierarchy",
filePath: "src/handler.rs",
line: 45,
character: 8
)
2. 着信呼び出し(これを呼び出すのは何か?)
LSP(
operation: "incomingCalls",
filePath: "src/handler.rs",
line: 45,
character: 8
)
3. 発信呼び出し(これが呼び出すのは何か?)
LSP(
operation: "outgoingCalls",
filePath: "src/handler.rs",
line: 45,
character: 8
)
ワークフロー
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
出力形式
着信呼び出し(これを呼び出すのは何か?)
## Callers of `process_request`
main
└── run_server
└── handle_connection
└── process_request ◄── YOU ARE HERE
発信呼び出し(これが呼び出すのは何か?)
## 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
双方向(両方)
## Call Graph for `process_request`
┌─────────────────┐
│ main │
└────────┬────────┘
│
┌────────▼────────┐
│ run_server │
└────────┬────────┘
│
┌────────▼────────┐
│handle_connection│
└────────┬────────┘
│
┌────────────────────┼────────────────────┐
│ │ │
┌───────▼───────┐ ┌───────▼───────┐ ┌───────▼───────┐
│ parse_headers │ │ authenticate │ │send_response │
└───────────────┘ └───────┬───────┘ └───────────────┘
│
┌───────┴───────┐
│ │
┌──────▼──────┐ ┌──────▼──────┐
│ check_token │ │ load_user │
└─────────────┘ └─────────────┘
分析の洞察
呼び出しグラフを生成した後、次の洞察を提示します。
## 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)
よくあるパターン
| ユーザーの発言 | 方向 | ユースケース |
|---|---|---|
| 「X を呼び出すのは何か?」 | 着信 | 影響分析 |
| 「X は何を呼び出すか?」 | 発信 | 実装の理解 |
| 「呼び出しグラフを表示して」 | 両方 | 全体像 |
| 「main から X までたどって」 | 発信 | 実行パス |
可視化オプション
| スタイル | 最適な用途 |
|---|---|
| ツリー(デフォルト) | シンプルな階層 |
| ボックス図 | 複雑な関係 |
| フラットリスト | 接続が多い場合 |
| 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
関連スキル
| 場合 | 参照先 |
|---|---|
| 定義を検索する | rust-code-navigator |
| プロジェクト構造 | rust-symbol-analyzer |
| トレイトの実装 | rust-trait-explorer |
| 安全なリファクタリング | rust-refactor-helper |
コメント
Markdown 対応