
Rust Refactor Helper
Run LSP-backed Rust refactors—rename, extract, inline, and move—with reference analysis and optional dry-run before editing.
Overview
Rust Refactor Helper is an agent skill most often used in Build (also Ship, Operate) that performs safe Rust refactors using LSP reference analysis before rename, extract, inline, or move operations.
Install
npx skills add https://github.com/actionbook/rust-skills --skill rust-refactor-helperWhat is this skill?
- Four actions: rename, extract-fn, inline, and move symbol to another module
- Pre-refactor LSP chain: goToDefinition, findReferences, hover, and incomingCalls for impact analysis
- Dry-run flag to preview edits before applying changes across categorized reference files
- Slash command `/rust-refactor-helper` with argument-hint for action and target
- Allowed-tools scoped to LSP, Read, Glob, Grep, and Edit for safe in-repo refactors
- 4 refactor actions: rename, extract-fn, inline, move
Adoption & trust: 882 installs on skills.sh; 1.2k GitHub stars; 2/3 security scanners passed (skills.sh audits).
What problem does it solve?
You need to rename or restructure Rust symbols but fear breaking callers you cannot see from one file.
Who is it for?
Solo builders refactoring Rust services or CLIs who already have rust-analyzer/LSP wired in the agent environment.
Skip if: Greenfield scaffolding from scratch, non-Rust projects, or refactors when LSP is unavailable—use manual grep and cargo check instead.
When should I use this skill?
Triggers on /refactor, rename symbol, move function, extract, 重构, 重命名, 提取函数, 安全重构
What do I get? / Deliverables
You get an LSP-scoped impact map and applied (or dry-run) edits across all references so the crate stays consistent before you run tests.
- Multi-file edits for the requested refactor
- Pre-refactor reference and call-hierarchy analysis
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
Refactoring Rust modules and symbols is core backend build work; canonical shelf is build/backend where Rust code lives. Targets Rust crate structure, symbols, and modules via LSP—not frontend or deploy pipelines.
Where it fits
Rename parse_config to load_config across the crate after LSP findReferences.
Extract lines 20–35 in main.rs into a dedicated function before adding tests.
Inline a thin wrapper discovered during pre-release API cleanup.
Move UserService into src/services/ without leaving stale imports.
How it compares
Use instead of blind multi-file search-replace when rust-analyzer can enumerate references and call hierarchy.
Common Questions / FAQ
Who is rust-refactor-helper for?
Indie and solo developers shipping Rust backends or CLIs who want agent-assisted refactors grounded in LSP references, not guesswork.
When should I use rust-refactor-helper?
During Build when renaming config loaders, extracting helpers, or moving types between modules; during Ship review when cleaning up API surfaces; during Operate when iterating on hot paths—always with /refactor or rename/move triggers.
Is rust-refactor-helper safe to install?
It edits project files via allowed Edit tools; review the Security Audits panel on this page and run cargo test/check after any refactor.
SKILL.md
READMESKILL.md - Rust Refactor Helper
# 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 │