rust-refactor-helper
0
总安装量
19
周安装量
安装命令
npx skills add https://github.com/actionbook/rust-skills --skill rust-refactor-helper
Agent 安装分布
opencode
16
gemini-cli
16
claude-code
15
codex
15
github-copilot
14
cursor
11
Skill 文档
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 |