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

Add an article documenting auto importing for Java code #2688

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

WispySparks
Copy link
Contributor

Resolves #2675

Copy link
Collaborator

@sciencewhiz sciencewhiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm struggling to see why this is useful enough for an frc-docs article. This seems fairly niche to me.


.. code-block:: json

"editor.codeActionsOnSave": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between this and "java.saveActions.organizeImports": true, which can also be set in the preferences gui?

Copy link
Contributor Author

@WispySparks WispySparks Aug 3, 2024

Choose a reason for hiding this comment

The 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/docs/software/vscode-overview/organize-imports.rst Outdated Show resolved Hide resolved
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.
Copy link
Collaborator

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

Copy link
Contributor Author

@WispySparks WispySparks Aug 3, 2024

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?

Copy link
Contributor

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

Copy link
Contributor Author

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).

Copy link
Contributor

@Gold856 Gold856 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A note should be added that syntax errors can cause auto-importing to delete imports that are actually used. Basically, any syntax error in a given scope will cause the extension to not register referenced imports in that scope, so if the only use of an import is in the scope where the syntax error is, that import will be removed. Once the syntax error is fixed, auto-import will fix up everything.

Copy link
Contributor

@spacey-sooty spacey-sooty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is common enough to be mentioned in frc-docs then IMO it should instead be added to the templates vscode settings

@WispySparks
Copy link
Contributor Author

WispySparks commented Aug 6, 2024

If this is common enough to be mentioned in frc-docs then IMO it should instead be added to the templates vscode settings

I asked about that but it seems that people would rather have it documented and not be the default.

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

Successfully merging this pull request may close these issues.

Document usage of VSCode's auto importer for Java
4 participants