rust-code-navigator について
Language Server Protocol の操作で Rust コードベースを調べるスキルです。定義や参照、シンボルの情報を確認したい開発者向けです。
主な機能
- 01シンボル定義への移動
- 02シンボル参照の検索
- 03型とドキュメントの確認
- 04ワークスペースシンボルの検索
活用シーン
- 01構造体や関数の定義の特定
- 02リファクタリング前の使用箇所確認
- 03シンボルの型とドキュメントの確認
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ actionbook/ rust-skills --skill rust-code-navigatorインストール後、Claude Code で/rust-code-navigatorを入力して読み込まれたか確認します。
詳細
Rust コードナビゲーター
Language Server Protocol を使用して、大規模な Rust コードベースを効率よくナビゲートします。
使用方法
/rust-code-navigator <symbol> [in file.rs:line]
例:
/rust-code-navigator parse_config- parse_config の定義を検索します/rust-code-navigator MyStruct in src/lib.rs:42- 指定した場所からナビゲートします
LSP 操作
1. 定義へ移動
シンボルが定義されている場所を検索します。
LSP(
operation: "goToDefinition",
filePath: "src/main.rs",
line: 25,
character: 10
)
使用する場面:
- ユーザーが「X はどこで定義されていますか?」と尋ねた場合
- ユーザーが型や関数を理解したい場合
- Ctrl キーを押しながらクリックする操作に相当します
2. 参照を検索
シンボルが使われている箇所をすべて検索します。
LSP(
operation: "findReferences",
filePath: "src/lib.rs",
line: 15,
character: 8
)
使用する場面:
- ユーザーが「X はどこで使われていますか?」と尋ねた場合
- リファクタリングや名前変更の前
- 変更の影響を把握する場合
3. ホバー情報
シンボルの型とドキュメントを取得します。
LSP(
operation: "hover",
filePath: "src/main.rs",
line: 30,
character: 15
)
使用する場面:
- ユーザーが「X の型は何ですか?」と尋ねた場合
- ユーザーがドキュメントを確認したい場合
- 型を手早く確認する場合
ワークフロー
User: "Where is the Config struct defined?"
│
▼
[1] Search for "Config" in workspace
LSP(operation: "workspaceSymbol", ...)
│
▼
[2] If multiple results, ask user to clarify
│
▼
[3] Go to definition
LSP(operation: "goToDefinition", ...)
│
▼
[4] Show file path and context
Read surrounding code for context
出力形式
定義が見つかった場合
## Config (struct)
**Defined in:** `src/config.rs:15`
```rust
#[derive(Debug, Clone)]
pub struct Config {
pub name: String,
pub port: u16,
pub debug: bool,
}
```
**Documentation:** Configuration for the application server.
参照が見つかった場合
## References to `Config` (5 found)
| Location | Context |
|----------|---------|
| src/main.rs:10 | `let config = Config::load()?;` |
| src/server.rs:25 | `fn new(config: Config) -> Self` |
| src/server.rs:42 | `self.config.port` |
| src/tests.rs:15 | `Config::default()` |
| src/cli.rs:8 | `config: Option<Config>` |
よくあるパターン
| ユーザーの発言 | LSP 操作 |
|---|---|
| 「X はどこで定義されていますか?」 | goToDefinition |
| 「X はどこで使われていますか?」 | findReferences |
| 「X の型は何ですか?」 | hover |
| 「すべての構造体を検索してください」 | workspaceSymbol |
| 「このファイルには何がありますか?」 | documentSymbol |
エラー処理
| エラー | 原因 | 解決策 |
|---|---|---|
| "LSP サーバーがありません" | rust-analyzer が実行されていない | rustup component add rust-analyzer を提案します |
| "シンボルが見つかりません" | 入力ミス、またはスコープ外 | まず workspaceSymbol で検索します |
| "定義が複数あります" | ジェネリクスまたはマクロ | すべて表示し、ユーザーに選択してもらいます |
関連スキル
| 場面 | 参照先 |
|---|---|
| 呼び出し関係 | rust-call-graph |
| プロジェクト構造 | rust-symbol-analyzer |
| トレイトの実装 | rust-trait-explorer |
| 安全なリファクタリング | rust-refactor-helper |
コメント
Markdown 対応