mcpField
R
rust-call-graph

rust-call-graph

github.com/actionbook開発1.6k3.2k 回インストール9 週間前に更新
リポジトリ

rust-call-graph について

LSP の呼び出し階層操作で Rust 関数間の関係を可視化するスキルです。方向と深さを指定し、呼び出し元や呼び出し先、両方を調べられます。

主な機能

  1. 01呼び出し元と呼び出し先の表示
  2. 02探索方向の指定
  3. 03グラフの深さの設定
  4. 04Mermaid 図として出力

活用シーン

  1. 01関数の呼び出し元を追跡
  2. 02関数が呼び出す関数を確認
  3. 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

コメント