You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the above extension pack to create a new Java project with no build tools, a project is initialised with a default src/App.java entry point.
If I create a new .java file with this vscode-java extension enabled, I helpfully get an outline/snippet inserted into the document for creating a new class (or interface etc.) based on the filename.
However, this is reliant on the vscode-java extension being activated. In the case of a project with no build tools, and therefore not meeting any of the existing activationEvents, then the extension only activates when an existing file using the Java language has been opened.
In the case that the first action is creating a new .java file, the file is created and the extension launches but without inserting the outline/snipped for the class (or interface etc.).
This behaviour can appear to end-users that VSCode sometimes inserts the outline for a Java class and sometimes does not.
Possible solutions
I can think of two possible solutions.
Expand activationEvents to activate the extension when .java file exists somewhere in the project. I am proposing a pattern of src/**/*.java to match src/App.java or src/module/App.java. With this change the extension will activate when the workspace opens, rather than being reliant on a .java file being opened first.
When the extension is activated, check to see if there is an open (or there are existing) .java file(s) which are empty and apply the outline/snipped based on the same conditions as already exist.
Proposed solution
I am proposing a solution based on (1) above, which will launch the extension where a .java file exists within a src directory. I have chosen this because it matches the default project structure created when creating a new Java project with no build tools using the extension pack above.
A limitation of this solution is that it will not work for all project structures. I would be open to modifying this so that the extension is enabled if .java files exist anywhere in the workspace, however I am not clear if there are drawbacks to this approach.
The text was updated successfully, but these errors were encountered:
I guess the workaround is the class snippet once it finishes loading. We put quite a bit of work into making the snippets much better. The real problem, as you've discovered is that if the the activation event for the extension is the file creation, we're already too late to register our client-side logic 😆
Only activating when build files are detected or a Java source file is opened has been the expected behaviour for a while. I suspect because as an installed extension, we'd like to activate only when we're absolutely sure we're needed. When a project contains known build files (pom.xml, build.gradle, .classpath), we know we should activate, and do so purely through detecting those files. When there's only Java source files, it's more difficult. Are they sample files, or maybe the user doesn't want Java support right now. The safer way is to activate when a Java source file is actually opened, as that makes it more clear. The downside is the delayed activation means that certain features may not be immediately available, or we won't register handlers in time.
Update: I think I like (2) a little more, as it avoids having us activate more often.
Problem
I am using this extension as part of the recommended by VSCode Extension Pack for Java extension.
When using the above extension pack to create a new Java project with no build tools, a project is initialised with a default
src/App.java
entry point.If I create a new .java file with this vscode-java extension enabled, I helpfully get an outline/snippet inserted into the document for creating a new class (or interface etc.) based on the filename.
However, this is reliant on the vscode-java extension being activated. In the case of a project with no build tools, and therefore not meeting any of the existing
activationEvents
, then the extension only activates when an existing file using the Java language has been opened.In the case that the first action is creating a new
.java
file, the file is created and the extension launches but without inserting the outline/snipped for the class (or interface etc.).This behaviour can appear to end-users that VSCode sometimes inserts the outline for a Java class and sometimes does not.
Possible solutions
I can think of two possible solutions.
Expand
activationEvents
to activate the extension when .java file exists somewhere in the project. I am proposing a pattern ofsrc/**/*.java
to matchsrc/App.java
orsrc/module/App.java
. With this change the extension will activate when the workspace opens, rather than being reliant on a.java
file being opened first.When the extension is activated, check to see if there is an open (or there are existing) .java file(s) which are empty and apply the outline/snipped based on the same conditions as already exist.
Proposed solution
I am proposing a solution based on (1) above, which will launch the extension where a .java file exists within a src directory. I have chosen this because it matches the default project structure created when creating a new Java project with no build tools using the extension pack above.
A limitation of this solution is that it will not work for all project structures. I would be open to modifying this so that the extension is enabled if .java files exist anywhere in the workspace, however I am not clear if there are drawbacks to this approach.
The text was updated successfully, but these errors were encountered: