Java on Visual Studio Code Update – April 2020

Xiaokai He

Welcome back to the April update of Java on Visual Studio Code.

In this update, we will show you the effect of our latest performance improvements. You can also see new Java 14 support and semantic highlighting. We’d also like to show you how to easily create new Java class, perform rename refactoring from file explorer and preview the proposed changes before committing. On to the update.

Performance improvement

If you’ve followed our update last month, we’ve enabled parallel dependency download to improve project loading performance as well as syntax mode. In this release, we’ve enabled syntax server for all project. You will be able to see the big difference on how fast you can do code navigation after opening a new project below.

Image syntax server startup

The idea is since building and indexing the project takes a long time, it’s annoying for our developers to wait. With the help of syntax server, instead of waiting for all the dependencies to be downloaded, you can use the features listed below right away:

  • Syntax Highlighting & Syntax Errors
  • Code Navigation (Go to Definition, etc.)
  • Documentation (Hover to See Javadoc)
  • Code Structures (Outline, Folding Range, etc.)

Once the full language server is ready, the syntax server would be turned off automatically.

Java 14 Support

Java 14 is out and is supported by the language server now. To use the preview features, you may need to modify your project settings.

Maven – modify pom.xml:

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <configuration>
            <release>14</release>
            <compilerArgs>--enable-preview</compilerArgs>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>

Gradle:

sourceCompatibility = 14

tasks.withType(JavaCompile) {
    options.compilerArgs += '--enable-preview'
}
tasks.withType(Test) {
    jvmArgs += "--enable-preview"
}

Note: if you are modifying a project that was already opened in VS Code before, you may need to force clean the workspace and reload. To do so, run command Java: Clean the Java language server workspace.

Semantic Highlighting

As you read and write code, syntax highlighting is a very important feature which allows you to read code more efficiently. However, since syntax highlighting colors the text based on lexical rules, it’s difficult to make it accurate for all scenarios. This month, VS Code Java brings semantic highlighting which enriches the syntax coloring based on symbol information from Java language service that has the full understanding of the project. Below is just one example, left is the behavior after enabling semantic highlighting and right is the one with only syntax highlighting.

Image semantic highlighting

To enable semantic highlighting, you can toggle the the `java.semanticHighlighting.enabled` preference. You will also be prompted to enable or disable it on startup:

Image semantic highlighting switch

You can also find more details of Java semantic highlighting here.

Create New Class from File Explorer

Here to mention a new way of creating a class. Now, when you create a .java file in the File Explorer, the language server will automatically generate the class body, and fill the package info for you:

Image create class

You can also create interfaceenum, and record in the same way.

Rename Refactoring and Preview

Now you can do rename refactoring from file explorer. And for each refactoring, you now have the option to preview the changes before committing it to your code base.

Image preview rename explorer

We’re also working on other refactoring, such as move from the file explorer, please stay tuned.

More improvements

The latest updates also brings a lot of other enhancements for Java experience in Visual Studio Code.

  1. Improved support for Gradle projects
  2. Improved organize import to resolve static imports and asterisk (*) wildcard character.
  3. New extension from Red Hat, Community Server Connectors brings better support for Apache Felix, Karaf and Tomcat.
  4. Skipped tests can be toggled out in the test report
  5. New documents are added to our official site.

Try it out

Please don’t hesitate to give it a try! Your feedback and suggestions are very important to us and will help shape our product in future.

1 comment

Discussion is closed. Login to edit/delete existing comments.

  • Amol Soneji 1

    This is the best update of all for Java on Visual Studio Code. The new symantic highlighter will make coding Java a lot more comfortable for me, and would make the development time of Java programs much easier and more efficient on Visual Studio Code.

Feedback usabilla icon