-
Notifications
You must be signed in to change notification settings - Fork 264
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
Add an article documenting auto importing for Java code #2688
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Organize Imports | ||
================ | ||
|
||
Visual Studio Code provides many settings to speed up programming. The Java extensions installed by WPILib allow for a setting to automatically insert the correct imports and organize them in your Java code when that file is saved. To enable this feature, first navigate to the user settings by opening the command palette with :kbd:`Ctrl+Shift+P`, then type User Settings (JSON) and press enter. Finally, add this section of code to the end of the user settings. | ||
|
||
.. code-block:: json | ||
|
||
"editor.codeActionsOnSave": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the difference between this and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure as I haven't heard of that option before but it looks like it's less reliable? redhat-developer/vscode-java#2207 |
||
"source.organizeImports": "explicit" | ||
}, | ||
|
||
The end result should look something like this. | ||
|
||
.. image:: images/organize-imports/settings.png | ||
WispySparks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Now whenever you save your files with :kbd:`Ctrl+S` or by clicking Save under the File dropdown, the necessary imports will be automatically inserted into your Java code for any classes you're using. If there is an ambiguous import, a dropdown will be provided for the user to select the correct one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In most cases, the imports are put in automatically as code is written. The main benefit seems to be the organizational aspect, But it seems like someone who cares that much would also want to use a full code formatter, which we have an article for. https://docs.wpilib.org/en/stable/docs/software/advanced-gradlerio/code-formatting.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my experience a lot of my imports are put in automatically through this setting and less so through the intellisense. The move for this article came from a discussion on the frc discord that a majority of people aren't aware of the auto import feature which this article aims to document. It also alleviates concerns when WPILib wants to move classes to different packages and break users' imports. Since it's so small perhaps it would be better suited to be added to an existing article?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whats the benefit of people knowing this option exists? Why does it justify maintaining a docs article
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it is helpful when coding and helps people from having to type imports manually which is pushback for WPILib to move classes around to different packages. Since it is such a small section I would be more than happy to add it to an existing VSCode article I'm just not sure which one would be best. I don't believe the maintenance would be high as this option has stayed the same the entire time I've been using VSCode (4 years).