rust-symbol-analyzer について
rust-symbol-analyzer は、Rust のファイルやプロジェクト全体のシンボルと構造を調べるスキルです。LSP のドキュメントシンボルとワークスペースシンボルを使い、階層、複雑度指標、内部依存関係を示します。
主な機能
- 01ファイルまたはワークスペースのシンボル解析
- 02シンボル種別による絞り込み
- 03入れ子になったシンボル階層の表示
- 04ファイルの複雑度指標の報告
- 05内部依存関係の可視化
活用シーン
- 01Rust プロジェクトのモジュール構造の確認
- 02ワークスペース内の trait や関数の一覧
- 03単一ソースファイルのシンボル調査
- 04複雑度や依存関係が大きいファイルの特定
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ actionbook/ rust-skills --skill rust-symbol-analyzerインストール後、Claude Code で/rust-symbol-analyzerを入力して読み込まれたか確認します。
詳細
Rust シンボルアナライザー
Rust コードベース全体のシンボルを調べて、プロジェクトの構造を分析します。
使用方法
/rust-symbol-analyzer [file.rs] [--type struct|trait|fn|mod]
例:
/rust-symbol-analyzer- プロジェクト全体を分析します/rust-symbol-analyzer src/lib.rs- 単一ファイルを分析します/rust-symbol-analyzer --type trait- プロジェクト内のすべてのトレイトを一覧表示します
LSP 操作
1. ドキュメントシンボル(単一ファイル)
ファイル内のすべてのシンボルとその階層を取得します。
LSP(
operation: "documentSymbol",
filePath: "src/lib.rs",
line: 1,
character: 1
)
戻り値: モジュール、構造体、関数などのネストされた構造です。
2. ワークスペースシンボル(プロジェクト全体)
ワークスペース全体からシンボルを検索します。
LSP(
operation: "workspaceSymbol",
filePath: "src/lib.rs",
line: 1,
character: 1
)
注: クエリは操作コンテキストから暗黙的に指定されます。
ワークフロー
User: "What's the structure of this project?"
│
▼
[1] Find all Rust files
Glob("**/*.rs")
│
▼
[2] Get symbols from each key file
LSP(documentSymbol) for lib.rs, main.rs
│
▼
[3] Categorize by type
│
▼
[4] Generate structure visualization
出力形式
プロジェクトの概要
## Project Structure: my-project
### Modules
├── src/
│ ├── lib.rs (root)
│ ├── config/
│ │ ├── mod.rs
│ │ └── parser.rs
│ ├── handlers/
│ │ ├── mod.rs
│ │ ├── auth.rs
│ │ └── api.rs
│ └── models/
│ ├── mod.rs
│ ├── user.rs
│ └── order.rs
└── tests/
└── integration.rs
シンボルの種類別
## Symbols by Type
### Structs (12)
| Name | Location | Fields | Derives |
|------|----------|--------|---------|
| Config | src/config.rs:10 | 5 | Debug, Clone |
| User | src/models/user.rs:8 | 4 | Debug, Serialize |
| Order | src/models/order.rs:15 | 6 | Debug, Serialize |
| ... | | | |
### Traits (4)
| Name | Location | Methods | Implementors |
|------|----------|---------|--------------|
| Handler | src/handlers/mod.rs:5 | 3 | AuthHandler, ApiHandler |
| Repository | src/db/mod.rs:12 | 5 | UserRepo, OrderRepo |
| ... | | | |
### Functions (25)
| Name | Location | Visibility | Async |
|------|----------|------------|-------|
| main | src/main.rs:10 | pub | yes |
| parse_config | src/config.rs:45 | pub | no |
| ... | | | |
### Enums (6)
| Name | Location | Variants |
|------|----------|----------|
| Error | src/error.rs:5 | 8 |
| Status | src/models/order.rs:5 | 4 |
| ... | | |
単一ファイルの分析
## src/handlers/auth.rs
### Symbols Hierarchy
mod auth
├── struct AuthHandler
│ ├── field: config: Config
│ ├── field: db: Pool
│ └── impl AuthHandler
│ ├── fn new(config, db) -> Self
│ ├── fn authenticate(&self, token) -> Result<User>
│ └── fn refresh_token(&self, user) -> Result<Token>
├── struct Token
│ ├── field: value: String
│ └── field: expires: DateTime
├── enum AuthError
│ ├── InvalidToken
│ ├── Expired
│ └── Unauthorized
└── impl Handler for AuthHandler
├── fn handle(&self, req) -> Response
└── fn name(&self) -> &str
分析機能
複雑度メトリクス
## Complexity Analysis
| File | Structs | Functions | Lines | Complexity |
|------|---------|-----------|-------|------------|
| src/handlers/auth.rs | 2 | 8 | 150 | Medium |
| src/models/user.rs | 3 | 12 | 200 | High |
| src/config.rs | 1 | 3 | 50 | Low |
**Hotspots:** Files with high complexity that may need refactoring
- src/handlers/api.rs (15 functions, 300 lines)
依存関係の分析
## Internal Dependencies
auth.rs
├── imports from: config.rs, models/user.rs, db/mod.rs
└── imported by: main.rs, handlers/mod.rs
user.rs
├── imports from: (none - leaf module)
└── imported by: auth.rs, api.rs, tests/
シンボルの種類
| 種類 | アイコン | LSP 種別 |
|---|---|---|
| モジュール | 📦 | Module |
| 構造体 | 🏗️ | Struct |
| 列挙型 | 🔢 | Enum |
| トレイト | 📜 | Interface |
| 関数 | ⚡ | Function |
| メソッド | 🔧 | Method |
| 定数 | 🔒 | Constant |
| フィールド | 📎 | Field |
よくある質問
| ユーザーの発言 | 分析 |
|---|---|
| 「このプロジェクトにはどのような構造体がありますか?」 | workspaceSymbol + filter |
| 「src/lib.rs の構造を表示して」 | documentSymbol |
| 「すべての非同期関数を検索して」 | workspaceSymbol + async filter |
| 「公開 API を一覧表示して」 | documentSymbol + pub filter |
関連スキル
| 場合 | 参照先 |
|---|---|
| シンボルへ移動する | rust-code-navigator |
| 呼び出し関係を調べる | rust-call-graph |
| トレイトの実装を調べる | rust-trait-explorer |
| 安全にリファクタリングする | rust-refactor-helper |
コメント
Markdown 対応