Refactor Buddy adds practical refactor shortcuts for VS Code. It helps when a language server supports a refactor, but VS Code does not pick the right selection range or filters out the action because it is not marked as preferred.
Features
- Smart Extract Variable
- Smart Extract Function
- Smart Inline
- Automatic selection expansion when the editor has no selection
- Action selection by querying the active language server
- Works with TypeScript and JavaScript through TS Server
- Works with Kotlin and Rust when their language servers expose matching refactor actions
Commands
| Command | Default keybinding used by the local setup |
|---|---|
refactor-buddy.extractVariable |
Cmd+Alt+V / Cmd+Alt+C |
refactor-buddy.extractFunction |
Cmd+Alt+M |
refactor-buddy.inline |
Cmd+Alt+N |
How It Works
Refactor Buddy does not implement a full compiler-grade refactoring engine. It:
- Uses VS Code selection ranges or a lightweight fallback to select the likely expression.
- Calls
vscode.executeCodeActionProviderfor the current language. - Picks the best matching extract or inline action by code action kind and title.
- Applies the edit or command returned by the language server.
This keeps the extension small and lets Kotlin Server, rust-analyzer, and TS Server remain the source of truth.
Language Limits
If the active language server returns no matching action, Refactor Buddy cannot create that refactor by itself. Open Output: Refactor Buddy to see the exact actions returned for the current selection.
For Kotlin, this means the result depends on JetBrains Kotlin Server or another Kotlin language server. For Rust, it depends on rust-analyzer assists exposed through VS Code code actions.
Troubleshooting
After installing or updating the extension, run:
Developer: Reload Window
Then retry the command and inspect:
Output -> Refactor Buddy
If the log shows actions=<none>, the language server did not provide a matching refactor for that selection.