rust-refactor-helper by actionbook/rust-skills
npx skills add https://github.com/actionbook/rust-skills --skill 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广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
/rust-refactor-helper move UserService src/services/# 重命名前查找所有引用
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
)
User: "Rename parse_config to 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 (仅预览)
- [ ] 应用更改
User: "Extract lines 20-35 in main.rs to a function"
│
▼
[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)?;
```
User: "Move UserService to 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 |
| Trait 实现 | rust-trait-explorer |
每周安装次数
43
代码仓库
GitHub 星标数
828
首次出现
Jan 23, 2026
安全审计
安装于
gemini-cli40
opencode40
codex39
github-copilot36
claude-code34
cursor31
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 |
Weekly Installs
43
Repository
GitHub Stars
828
First Seen
Jan 23, 2026
Security Audits
Gen Agent Trust HubFailSocketPassSnykPass
Installed on
gemini-cli40
opencode40
codex39
github-copilot36
claude-code34
cursor31
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
116,600 周安装