rust-refactor-helper
LSP(Language Server Protocol)の分析に基づき、Rustのコードを安全にリファクタリング(名前変更、関数移動、抽出など)する作業を、コマンドやメニュー操作で効率的に支援するSkill。
📜 元の英語説明(参考)
Safe Rust refactoring with LSP analysis. Triggers on: /refactor, rename symbol, move function, extract, 重构, 重命名, 提取函数, 安全重构
🇯🇵 日本人クリエイター向け解説
LSP(Language Server Protocol)の分析に基づき、Rustのコードを安全にリファクタリング(名前変更、関数移動、抽出など)する作業を、コマンドやメニュー操作で効率的に支援するSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o rust-refactor-helper.zip https://jpskill.com/download/9280.zip && unzip -o rust-refactor-helper.zip && rm rust-refactor-helper.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/9280.zip -OutFile "$d\rust-refactor-helper.zip"; Expand-Archive "$d\rust-refactor-helper.zip" -DestinationPath $d -Force; ri "$d\rust-refactor-helper.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
rust-refactor-helper.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
rust-refactor-helperフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
Rust Refactor Helper
包括的な影響分析によって安全なリファクタリングを実行します。
使い方
/rust-refactor-helper <action> <target> [--dry-run]
アクション:
rename <old> <new>- シンボル名の変更extract-fn <selection>- 関数への抽出inline <fn>- 関数のインライン化move <symbol> <dest>- モジュールへの移動
例:
/rust-refactor-helper rename parse_config load_config/rust-refactor-helper extract-fn src/main.rs:20-35/rust-refactor-helper move UserService src/services/
使用される LSP 操作
リファクタリング前の分析
# 名前を変更する前にすべての参照を検索
LSP(
operation: "findReferences",
filePath: "src/lib.rs",
line: 25,
character: 8
)
# シンボル情報を取得
LSP(
operation: "hover",
filePath: "src/lib.rs",
line: 25,
character: 8
)
# 移動操作の呼び出し階層を確認
LSP(
operation: "incomingCalls",
filePath: "src/lib.rs",
line: 25,
character: 8
)
リファクタリングのワークフロー
1. シンボル名の変更
User: "parse_config を load_config に変更"
│
▼
[1] シンボルの定義を検索
LSP(goToDefinition)
│
▼
[2] すべての参照を検索
LSP(findReferences)
│
▼
[3] ファイルごとに分類
│
▼
[4] 競合を確認
- 'load_config' はすでに使用されていますか?
- マクロで生成された使用箇所はありますか?
│
▼
[5] 影響分析を表示 (--dry-run)
│
▼
[6] Edit ツールで変更を適用
出力:
## 名前変更: parse_config → load_config
### 影響分析
**定義:** src/config.rs:25
**参照数:** 8
| ファイル | 行 | コンテキスト | 変更 |
|------|------|---------|--------|
| src/config.rs | 25 | `pub fn parse_config(` | 定義 |
| src/config.rs | 45 | `parse_config(path)?` | 呼び出し |
| src/main.rs | 12 | `config::parse_config` | インポート |
| src/main.rs | 30 | `let cfg = parse_config(` | 呼び出し |
| src/lib.rs | 8 | `pub use config::parse_config` | 再エクスポート |
| tests/config_test.rs | 15 | `parse_config("test.toml")` | テスト |
| tests/config_test.rs | 25 | `parse_config("")` | テスト |
| docs/api.md | 42 | `parse_config` | ドキュメント |
### 潜在的な問題
⚠️ **ドキュメントの参照:** docs/api.md:42 は手動での更新が必要な場合があります
⚠️ **再エクスポート:** src/lib.rs:8 - パブリック API の変更
### 続行しますか?
- [x] --dry-run (プレビューのみ)
- [ ] 変更を適用
2. 関数への抽出
User: "main.rs の 20-35 行を関数に抽出"
│
▼
[1] 選択されたコードブロックを読み取る
│
▼
[2] 変数を分析
- どれが入力ですか? (ブロック内で使用されているが定義されていない)
- どれが出力ですか? (ブロック内で定義され、その後で使用されている)
- どれがローカルですか? (ブロック内でのみ定義され使用されている)
│
▼
[3] 関数のシグネチャを決定
│
▼
[4] アーリーリターン、ループなどを確認
│
▼
[5] 抽出された関数を生成
│
▼
[6] 元のコードを呼び出しで置き換える
出力:
## 関数への抽出: src/main.rs:20-35
### 選択されたコード
```rust
let file = File::open(&path)?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;
let config: Config = toml::from_str(&contents)?;
validate_config(&config)?;
```
### 分析
**入力:** path: &Path
**出力:** config: Config
**副作用:** ファイル I/O、エラーを返す可能性あり
### 抽出された関数
```rust
fn load_and_validate_config(path: &Path) -> Result<Config> {
let file = File::open(path)?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;
let config: Config = toml::from_str(&contents)?;
validate_config(&config)?;
Ok(config)
}
```
### 置換
```rust
let config = load_and_validate_config(&path)?;
```
3. シンボルの移動
User: "UserService を src/services/ に移動"
│
▼
[1] シンボルとそのすべての依存関係を検索
│
▼
[2] すべての参照 (呼び出し元) を検索
LSP(findReferences)
│
▼
[3] 必要なインポートの変更を分析
│
▼
[4] 循環依存関係を確認
│
▼
[5] 移動計画を生成
出力:
## 移動: UserService → src/services/user.rs
### 現在の場所
src/handlers/auth.rs:50-120
### 依存関係 (一緒に移動されます)
- struct UserService (50-80)
- impl UserService (82-120)
- const DEFAULT_TIMEOUT (48)
### 必要なインポートの変更
| ファイル | 現在 | 新規 |
|------|---------|-----|
| src/main.rs | `use handlers::auth::UserService` | `use services::user::UserService` |
| src/handlers/api.rs | `use super::auth::UserService` | `use crate::services::user::UserService` |
| tests/auth_test.rs | `use crate::handlers::auth::UserService` | `use crate::services::user::UserService` |
### 新しいファイル構造
```
src/
├── services/
│ ├── mod.rs (新規 - `pub mod user;` を追加)
│ └── user.rs (新規 - UserService がここに移動)
├── handlers/
│ └── auth.rs (UserService が削除)
```
### 循環依存関係のチェック
✅ 循環依存関係は検出されませんでした
安全性チェック
| チェック | 目的 |
|---|---|
| 参照の完全性 | すべての使用箇所が確実に検出されるようにする |
| 名前の競合 | 同じ名前の既存のシンボルを検出する |
| 可視性の変更 | pub/private スコープの変更がある場合に警告する |
| マクロで生成されたコード | マクロ内のコードについて警告する |
| ドキュメント | シンボルに言及しているドキュメントコメントにフラグを立てる |
| テストカバレッジ | 影響を受けるテストを表示する |
ドライランモード
最初に --dry-run を使用して変更をプレビューすることを常にお勧めします。
/rust-refactor-helper rename old_name new_name --dry-run
これにより、変更を適用せずにすべての変更が表示されます。
関連スキル
| いつ | 参照 |
|---|---|
| シンボルに移動 | rust-code-navigator |
| 呼び出しフローを理解 | rust-call-graph |
| プロジェクト構造 | rust-symbol-analyzer |
| トレイトの実装 | rust-trait-explorer |
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Rust Refactor Helper
Perform safe refactoring with comprehensive impact analysis.
Usage
/rust-refactor-helper <action> <target> [--dry-run]
Actions:
rename <old> <new>- Rename symbolextract-fn <selection>- Extract to functioninline <fn>- Inline functionmove <symbol> <dest>- Move to module
Examples:
/rust-refactor-helper rename parse_config load_config/rust-refactor-helper extract-fn src/main.rs:20-35/rust-refactor-helper move UserService src/services/
LSP Operations Used
Pre-Refactor Analysis
# Find all references before renaming
LSP(
operation: "findReferences",
filePath: "src/lib.rs",
line: 25,
character: 8
)
# Get symbol info
LSP(
operation: "hover",
filePath: "src/lib.rs",
line: 25,
character: 8
)
# Check call hierarchy for move operations
LSP(
operation: "incomingCalls",
filePath: "src/lib.rs",
line: 25,
character: 8
)
Refactoring Workflows
1. Rename Symbol
User: "Rename parse_config to load_config"
│
▼
[1] Find symbol definition
LSP(goToDefinition)
│
▼
[2] Find ALL references
LSP(findReferences)
│
▼
[3] Categorize by file
│
▼
[4] Check for conflicts
- Is 'load_config' already used?
- Are there macro-generated uses?
│
▼
[5] Show impact analysis (--dry-run)
│
▼
[6] Apply changes with Edit tool
Output:
## Rename: parse_config → load_config
### Impact Analysis
**Definition:** src/config.rs:25
**References found:** 8
| File | Line | Context | Change |
|------|------|---------|--------|
| src/config.rs | 25 | `pub fn parse_config(` | Definition |
| src/config.rs | 45 | `parse_config(path)?` | Call |
| src/main.rs | 12 | `config::parse_config` | Import |
| src/main.rs | 30 | `let cfg = parse_config(` | Call |
| src/lib.rs | 8 | `pub use config::parse_config` | Re-export |
| tests/config_test.rs | 15 | `parse_config("test.toml")` | Test |
| tests/config_test.rs | 25 | `parse_config("")` | Test |
| docs/api.md | 42 | `parse_config` | Documentation |
### Potential Issues
⚠️ **Documentation reference:** docs/api.md:42 may need manual update
⚠️ **Re-export:** src/lib.rs:8 - public API change
### Proceed?
- [x] --dry-run (preview only)
- [ ] Apply changes
2. Extract Function
User: "Extract lines 20-35 in main.rs to a function"
│
▼
[1] Read the selected code block
│
▼
[2] Analyze variables
- Which are inputs? (used but not defined in block)
- Which are outputs? (defined and used after block)
- Which are local? (defined and used only in block)
│
▼
[3] Determine function signature
│
▼
[4] Check for early returns, loops, etc.
│
▼
[5] Generate extracted function
│
▼
[6] Replace original code with call
Output:
## Extract Function: src/main.rs:20-35
### Selected Code
```rust
let file = File::open(&path)?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;
let config: Config = toml::from_str(&contents)?;
validate_config(&config)?;
```
### Analysis
**Inputs:** path: &Path
**Outputs:** config: Config
**Side Effects:** File I/O, may return error
### Extracted Function
```rust
fn load_and_validate_config(path: &Path) -> Result<Config> {
let file = File::open(path)?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;
let config: Config = toml::from_str(&contents)?;
validate_config(&config)?;
Ok(config)
}
```
### Replacement
```rust
let config = load_and_validate_config(&path)?;
```
3. Move Symbol
User: "Move UserService to src/services/"
│
▼
[1] Find symbol and all its dependencies
│
▼
[2] Find all references (callers)
LSP(findReferences)
│
▼
[3] Analyze import changes needed
│
▼
[4] Check for circular dependencies
│
▼
[5] Generate move plan
Output:
## Move: UserService → src/services/user.rs
### Current Location
src/handlers/auth.rs:50-120
### Dependencies (will be moved together)
- struct UserService (50-80)
- impl UserService (82-120)
- const DEFAULT_TIMEOUT (48)
### Import Changes Required
| File | Current | New |
|------|---------|-----|
| src/main.rs | `use handlers::auth::UserService` | `use services::user::UserService` |
| src/handlers/api.rs | `use super::auth::UserService` | `use crate::services::user::UserService` |
| tests/auth_test.rs | `use crate::handlers::auth::UserService` | `use crate::services::user::UserService` |
### New File Structure
```
src/
├── services/
│ ├── mod.rs (NEW - add `pub mod user;`)
│ └── user.rs (NEW - UserService moved here)
├── handlers/
│ └── auth.rs (UserService removed)
```
### Circular Dependency Check
✅ No circular dependencies detected
Safety Checks
| Check | Purpose |
|---|---|
| Reference completeness | Ensure all uses are found |
| Name conflicts | Detect existing symbols with same name |
| Visibility changes | Warn if pub/private scope changes |
| Macro-generated code | Warn about code in macros |
| Documentation | Flag doc comments mentioning symbol |
| Test coverage | Show affected tests |
Dry Run Mode
Always use --dry-run first to preview changes:
/rust-refactor-helper rename old_name new_name --dry-run
This shows all changes without applying them.
Related Skills
| When | See |
|---|---|
| Navigate to symbol | rust-code-navigator |
| Understand call flow | rust-call-graph |
| Project structure | rust-symbol-analyzer |
| Trait implementations | rust-trait-explorer |