PluginBench
Skill
Fail
Audit score 45

rust-refactor-helper

actionbook/rust-skills

Safe Rust refactoring with LSP-powered impact analysis and dry-run preview.

What is rust-refactor-helper?

Performs safe Rust refactoring operations (rename, extract function, inline, move) using Language Server Protocol analysis to find all references and detect conflicts before applying changes. Use this when you need to refactor code with confidence that all usages are updated correctly.

  • Rename symbols across all files with reference tracking and conflict detection
  • Extract code blocks into new functions with automatic signature generation
  • Inline functions by replacing calls with their body
  • Move symbols to different modules with import path updates
  • Preview all changes with --dry-run before applying
  • Detect potential issues: name conflicts, visibility changes, macro-generated code, documentation references

How to install rust-refactor-helper

npx skills add https://github.com/actionbook/rust-skills --skill rust-refactor-helper
Claude Code
Cursor
Windsurf
Cline

How to use rust-refactor-helper

  1. 1.Run the skill with an action and target: `/rust-refactor-helper <action> <target>`
  2. 2.Use `--dry-run` flag to preview changes without applying them
  3. 3.Review the impact analysis table showing all affected files and lines
  4. 4.Check the potential issues section for conflicts or visibility changes
  5. 5.Apply changes once you've verified the preview is correct

Use cases

Good for
  • Rename a function and automatically update all 8+ call sites across multiple files
  • Extract a 15-line configuration loading block into a reusable function with proper error handling
  • Move a service struct from handlers/ to services/ and fix all import paths in dependent files
  • Inline a simple utility function and verify no callers are broken
  • Preview refactoring impact on tests and documentation before committing
Who it's for
  • Rust developers refactoring existing codebases
  • Teams maintaining large Rust projects with many interdependencies
  • Anyone needing confidence that refactoring won't break hidden references

rust-refactor-helper FAQ

What if a symbol is used in a macro or generated code?

The skill warns about macro-generated uses in the potential issues section, since these may not be automatically updated. You'll need to manually verify or update macro invocations.

Can I rename a public function that's part of the API?

Yes, but the skill flags it as a potential issue since it's a breaking change. The impact analysis shows all re-exports and public uses so you can assess the scope.

Does --dry-run actually apply changes?

No, --dry-run only previews changes and shows the impact analysis table. You must run the command again without --dry-run to apply changes.

What happens if the new name already exists?

The skill detects name conflicts during the pre-refactor analysis and warns you before proceeding, preventing accidental overwrites.

Can I extract code that has early returns or loops?

Yes, the skill analyzes control flow and generates appropriate function signatures. It warns if the extraction is complex or may change behavior.

Full instructions (SKILL.md)

Source of truth, from actionbook/rust-skills.


name: rust-refactor-helper description: "Safe Rust refactoring with LSP analysis. Triggers on: /refactor, rename symbol, move function, extract, 重构, 重命名, 提取函数, 安全重构" argument-hint: "<action> <target> [--dry-run]" allowed-tools: ["LSP", "Read", "Glob", "Grep", "Edit"]

Rust Refactor Helper

Perform safe refactoring with comprehensive impact analysis.

Usage

/rust-refactor-helper <action> <target> [--dry-run]

Actions:

  • rename <old> <new> - Rename symbol
  • extract-fn <selection> - Extract to function
  • inline <fn> - Inline function
  • move <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

CheckPurpose
Reference completenessEnsure all uses are found
Name conflictsDetect existing symbols with same name
Visibility changesWarn if pub/private scope changes
Macro-generated codeWarn about code in macros
DocumentationFlag doc comments mentioning symbol
Test coverageShow 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

WhenSee
Navigate to symbolrust-code-navigator
Understand call flowrust-call-graph
Project structurerust-symbol-analyzer
Trait implementationsrust-trait-explorer

Related skills

More from actionbook/rust-skills and the wider catalog.

RUrust-router logo

rust-router

actionbook/rust-skills

Router skill for all Rust questions—directs to specialized language, design, and domain skills.

2.3k installsAudited
RUrust-skill-creator logo

rust-skill-creator

actionbook/rust-skills

Create dynamic skills for Rust crates and standard library documentation.

2.7k installs
RUrust-symbol-analyzer logo

rust-symbol-analyzer

actionbook/rust-skills

Analyze Rust project structure and list symbols (structs, traits, functions) using LSP.

2.8k installs
RUrust-trait-explorer logo

rust-trait-explorer

actionbook/rust-skills

Explore Rust trait implementations and polymorphic designs using LSP.

2.9k installsAudited
UNunsafe-checker logo

unsafe-checker

actionbook/rust-skills

Detects and reviews unsafe Rust code patterns, FFI calls, and memory safety issues.

2.9k installsAudited
ESesp32-firmware-engineer logo

esp32-firmware-engineer

adamlipecz/esp32-firmware-engineer-skill

ESP32 firmware engineering for ESP-IDF projects. Write, review, and debug embedded C/C++ code involving FreeRTOS tasks/queues/timers, GPIO/I2C/SPI/UART/ADC/PWM peripherals, TWAI/CAN, Wi-Fi/BLE networking, OTA updates, Secure Boot and flash encryption, LVGL display integration, build/flash/monitor workflows, logging, crash analysis, memory/code-size optimization, low-power sleep/wakeup design, on-device USB/serial service terminals, and board bring-up. Use when an agent is asked to implement ESP-IDF firmware features, review embedded changes for correctness or race conditions, investigate boot/runtime failures or Guru Meditation panics, interpret serial logs, fix build/link/flash problems, optimize RAM/flash usage, tune deep sleep/light sleep behavior, harden firmware for production, add a service console/CLI, integrate a display with LVGL, or diagnose hardware-software integration issues on ESP32-class devices.

722 installs