Automatically create keyboard shortcuts for each refactoring
Please make the refactorings contribute VSCode Commands so that users can configure shortcuts for them and preserve our state of flow, instead of having to use the context menu.
I spent an hour trying to find these commands because I couldn't believe they didn't exist.
Environment
- Operating System: Ubuntu
- JDK version: 21
- Visual Studio Code version: 1.85.1
- Java extension version: 1.25.1
Steps To Reproduce
- Open the Keyboard Shortcuts View
- Search for "Inline Local Variable" (or any other refactoring)
Current Result
No Java refactoring action appears.
Expected Result
A Java refactoring action should appear, so that we can configure a shortcut for it.
I think this is actually possible although it requires vscode-java to register some of the keybindings in the extension. However, it's possible for users to customize this. See https://code.visualstudio.com/docs/editor/refactoring#_keybindings-for-code-actions .
In your VS Code custom keybindings file, which can be accessed by clicking the "Open Keyboard Shortcuts (JSON)" button from the Keyboard Shortcuts preference page :
$HOME/.confg/Code/User/keybindings.json
// Place your key bindings in this file to override the defaultsauto[]
[
{
"command": "editor.action.codeAction",
"when": "editorTextFocus",
"args": {
"kind": "refactor.inline"
},
"key": "alt+shift+i"
}
]
You should see it show up in the Keyboard Shortcut preference page (and set the key to whatever you prefer) and it should work as expected. The only tricky part is figuring out what the kind is for the refactoring. There's no well documented place for this, but for now you can use :
https://github.com/eclipse-lsp4j/lsp4j/blob/main/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend#L2420-L2509 https://github.com/eclipse-jdtls/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/JavaCodeActionKind.java
Thanks!