Add "Generate constructor" option in "Show Fixes" options for fields
See original GitHub issueEnvironment
- Operating System: Linux x64 5.4.28-1-MANJARO
- JDK version: OpenJDK 11.0.6
- Visual Studio Code version: 1.43.2
- Java extension version: 0.59.0
Steps To Reproduce
In IntelliJ is possible to generate a constructor from fields very easily. This enhances productivity because in Spring Boot projects there’'s a lot of dependency injection through constructor. So usually we declare our dependencies as fields, then quick fix the field with a “Generate constructor” on them.
In VS Code this could be achieved through the Show Fixes
options, which can be triggered by selecting the field and hitting the keyboard shortcut for the Show Fixes popup. That popup could have an option called Generate Constructors...
that will open a list to choose which fields will be added in the constructor. But this option don’t exists in the Show Fixes
popup.
The Generate Constructors...
feature already exists, but it’s very unproductive to open this option. I have to right click on the editor and choose the option Source Action...
, which will open a popup with some items. One of those items is the Generate Constructors...
option.
The gif below shows how difficult it is to generate a constructor:
A productive approach would be to generate this constructor without any mouse interaction.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
You can bind source actions to a shortcut, for instance:
Make sure the key doesn’t conflict with an existing keybinding. It’s an editor-wide shortcut, nothing specific to vscode-java here.
Just go to keyboard shortcuts in the file -> preferences - > keyboard shortcuts and look for “generate constructor” and then bind your combination of keys.