rust-refactor-helper

zhanghandong/rust-skills · updated Apr 10, 2026

MDX-style export adds YAML metadata + attribution linking explainx.ai and this canonical listing URL.

$npx skills add https://github.com/zhanghandong/rust-skills --skill rust-refactor-helper
0 commentsdiscussion
summary

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

  • Supports four refactoring actions: rename symbol, extract function, inline function, and move to module
  • Performs pre-refactor analysis using LSP operations (find references, go to definition, call hierarchy) to identify all affected code locations
  • Generates detailed impact reports showing definition location, all references categorized by file, and potential issues like documentation updates or public API chan
skill.md

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

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
how to use rust-refactor-helper

How to use rust-refactor-helper on Cursor

AI-first code editor with Composer

1

Prerequisites

Before installing skills in Cursor, ensure your development environment meets these requirements:

  • Cursor installed and configured on your development machine
  • Node.js version 16.0+ with npm package manager (verify with node --version)
  • Active project directory or workspace where you want to add rust-refactor-helper
2

Execute installation command

Execute the skills CLI command in your project's root directory to begin installation:

$npx skills add https://github.com/zhanghandong/rust-skills --skill rust-refactor-helper

The skills CLI fetches rust-refactor-helper from GitHub repository zhanghandong/rust-skills and configures it for Cursor.

3

Select Cursor when prompted

The CLI will show a list of available agents. Use arrow keys to navigate and space to select Cursor:

◆ Which agents do you want to install to?
│ ── Universal (.agents/skills) ── always included ────
│ • Amp
│ • Antigravity
│ • Cline
│ • Codex
│ ●Cursor(selected)
│ • Cursor
│ • Windsurf
4

Verify installation

Confirm successful installation by checking the skill directory location:

.cursor/skills/rust-refactor-helper

Reload or restart Cursor to activate rust-refactor-helper. Access the skill through slash commands (e.g., /rust-refactor-helper) or your agent's skill management interface.

Security & Verification Notice

We perform automated surface-level scans (Gen AI Scanner, Socket, Snyk) during installation. These checks detect common vulnerabilities but do not guarantee complete security. Always review skill source code and verify the publisher's reputation before production use.

Skills execute code in your development environment. Always verify the publisher's identity, review recent commits, and test in isolated environments before production deployment.

List & Monetize Your Skill

Submit your Claude Code skill and start earning

GET_STARTED →

Use Cases

Task Automation & Efficiency

Automate repetitive workflows and reduce manual effort

Example

Generate reports, summarize documents, draft communications

Save 3-5 hours per week on routine tasks

Knowledge Enhancement

Learn new skills, understand complex topics, get expert guidance

Example

Explain concepts, provide examples, suggest learning resources

Accelerate learning and skill development by 2x

Quality Improvement

Enhance output quality through reviews, suggestions, and refinements

Example

Review drafts, suggest improvements, catch errors

Improve work quality by 30-40% with less effort

Implementation Guide

Prerequisites

  • Claude Desktop or compatible AI client with skill support
  • Clear understanding of task or problem to solve
  • Willingness to iterate and refine outputs

Time Estimate

15-45 minutes depending on use case complexity

Installation Steps

  1. 1.Install skill using provided installation command
  2. 2.Test with simple use case relevant to your work
  3. 3.Evaluate output quality and relevance
  4. 4.Iterate on prompts to improve results
  5. 5.Integrate into regular workflow if valuable

Common Pitfalls

  • Expecting perfect results without iteration
  • Not providing enough context in prompts
  • Using skill for tasks outside its intended scope
  • Accepting outputs without review and validation

Best Practices

✓ Do

  • +Start with clear, specific prompts
  • +Provide relevant context and constraints
  • +Review and refine all outputs before using
  • +Iterate to improve output quality
  • +Document successful prompt patterns

✗ Don't

  • Don't use without understanding skill limitations
  • Don't skip validation of outputs
  • Don't share sensitive information in prompts
  • Don't expect skill to replace human judgment

💡 Pro Tips

  • Be specific about desired format and style
  • Ask for multiple options to choose from
  • Request explanations to understand reasoning
  • Combine AI efficiency with human expertise

When to Use This

✓ Use When

Use when skill capabilities match your task, clear ROI on time saved, and you can validate outputs. Best for repetitive tasks, learning, and quality improvement.

✗ Avoid When

Avoid when task requires deep expertise you can't validate, involves sensitive decisions, or when learning process is more valuable than speed of completion.

Learning Path

  1. 1Familiarize yourself with skill capabilities and limitations
  2. 2Start with low-risk, non-critical tasks
  3. 3Progress to more complex and valuable use cases
  4. 4Build expertise through regular use and experimentation

Discussion

Product Hunt–style comments (not star reviews)
  • No comments yet — start the thread.
general reviews

Ratings

4.855 reviews
  • Nikhil Liu· Dec 20, 2024

    Registry listing for rust-refactor-helper matched our evaluation — installs cleanly and behaves as described in the markdown.

  • Amelia Okafor· Dec 20, 2024

    rust-refactor-helper has been reliable in day-to-day use. Documentation quality is above average for community skills.

  • Carlos Khanna· Dec 16, 2024

    rust-refactor-helper is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.

  • Nikhil Chen· Dec 16, 2024

    rust-refactor-helper reduced setup friction for our internal harness; good balance of opinion and flexibility.

  • Nikhil Martinez· Dec 12, 2024

    Useful defaults in rust-refactor-helper — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.

  • Amelia Haddad· Nov 19, 2024

    Keeps context tight: rust-refactor-helper is the kind of skill you can hand to a new teammate without a long onboarding doc.

  • Maya Abbas· Nov 11, 2024

    Useful defaults in rust-refactor-helper — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.

  • Amelia Chen· Nov 11, 2024

    rust-refactor-helper fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.

  • Daniel Ghosh· Nov 7, 2024

    I recommend rust-refactor-helper for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.

  • Aisha Johnson· Nov 7, 2024

    rust-refactor-helper is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.

showing 1-10 of 55

1 / 6