skills/rust-refactor-helper/SKILL.md
Safe Rust refactoring with LSP analysis. Triggers on: /refactor, rename symbol, move function, extract, 重构, 重命名, 提取函数, 安全重构
npx skillsauth add actionbook/rust-skills rust-refactor-helperInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Perform safe refactoring with comprehensive impact analysis.
/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 moduleExamples:
/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/# 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
)
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
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)?;
```
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
| 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 |
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.
| When | See | |------|-----| | Navigate to symbol | rust-code-navigator | | Understand call flow | rust-call-graph | | Project structure | rust-symbol-analyzer | | Trait implementations | rust-trait-explorer |
development
CRITICAL: Use for ALL Rust questions including errors, design, and coding. HIGHEST PRIORITY for: 比较, 对比, compare, vs, versus, 区别, difference, 最佳实践, best practice, tokio vs, async-std vs, 比较 tokio, 比较 async, Triggers on: Rust, cargo, rustc, crate, Cargo.toml, 意图分析, 问题分析, 语义分析, analyze intent, question analysis, compile error, borrow error, lifetime error, ownership error, type error, trait error, value moved, cannot borrow, does not live long enough, mismatched types, not satisfied, E0382, E0597, E0277, E0308, E0499, E0502, E0596, async, await, Send, Sync, tokio, concurrency, error handling, 编译错误, compile error, 所有权, ownership, 借用, borrow, 生命周期, lifetime, 类型错误, type error, 异步, async, 并发, concurrency, 错误处理, error handling, 问题, problem, question, 怎么用, how to use, 如何, how to, 为什么, why, 什么是, what is, 帮我写, help me write, 实现, implement, 解释, explain
development
Internal maintenance support for checking and fixing generated Rust skill documentation references. Use only when explicitly invoked by /fix-skill-docs.
development
Internal command support for dynamic Rust crate skill management. Use only when explicitly invoked by /sync-crate-skills, /clean-crate-skills, or /update-crate-skill.
tools
Internal support skill for agent-browser CLI workflows used by rust-learner, docs-researcher, and crate-researcher. Use only when browser automation is explicitly required.