Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically create keyboard shortcuts for each refactoring #3447

Open
klauswuestefeld opened this issue Dec 31, 2023 · 2 comments
Open

Automatically create keyboard shortcuts for each refactoring #3447

klauswuestefeld opened this issue Dec 31, 2023 · 2 comments

Comments

@klauswuestefeld
Copy link

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
  1. Open the Keyboard Shortcuts View
  2. 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.

@rgrunber
Copy link
Member

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

@rgrunber rgrunber changed the title [Feature Request] Keyboard shortcut for each refactoring Automatically create keyboard shortcuts for each refactoring Jan 12, 2024
@klauswuestefeld
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants