Serena Safe Refactor
Automated refactoring workflow that ensures safety by analyzing impact before making changes.
When to Apply
- •Renaming functions or classes
- •Changing function signatures
- •Extracting or moving code
- •Large-scale refactoring operations
Workflow
Phase 1: Impact Analysis
- •Use
serena_find_symbolto locate the target - •Use
serena_find_referencing_symbolsto find all usages - •Review impact scope
Phase 2: Preparation
- •Check for tests covering the target code
- •Identify potential breaking changes
- •Plan migration strategy if needed
Phase 3: Execution
- •Use
serena_rename_symbolfor safe renaming - •Use
serena_replace_symbol_bodyfor implementation changes - •Use
serena_replace_contentfor pattern-based changes
Phase 4: Verification
- •Run tests to verify changes
- •Check for compilation errors
- •Review affected files
Best Practices
- •Always find references before refactoring
- •Make atomic changes - one symbol at a time
- •Verify with tests after each change
- •Use
rename_symbolinstead ofreplace_contentwhen possible
Safety Checklist
- • All references found and reviewed
- • Tests exist for the target code
- • Breaking changes documented
- • Rollback plan prepared
Example Usage
typescript
// Safe rename of a function
const workflow = [
'serena_find_symbol("oldFunctionName")',
'serena_find_referencing_symbols("oldFunctionName")',
'serena_rename_symbol("oldFunctionName", "newFunctionName")',
];
Context
- •Learned from repeated refactoring patterns
- •Emphasizes safety and impact analysis
- •Confidence: High (based on 5+ observed usages)