Add --enable-preview option in Java in Visual Studio Code

A long time ago, the Java Extension Pack of Visual Studio Code (hereafter VS Code) now supports JDK 13.

When I tried JEP 355: Text Blocks (Preview), "Text Blocks is a preview feature and disabled by default. Use --enable-preview to enable I got the error. 2019-11-07_22h30_01.png

Yes, I thought I had to add --enable-preview, but how do I specify that for VS Code? I stopped for a moment, so I looked it up.

Since the above error occurred in a project using Maven, I was able to solve it by adding the following description to Maven's Compiler Plugin regardless of VSCode.

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    <configuration>
        <compilerArgs>--enable-preview</compilerArgs>
    </configuration>
</plugin>

In addition, JDT (Java Development Tool) included in Language Support for Java of Java Extension Pack. I was able to solve it by setting eclipse.org/jdt/). Reference: https://github.com/redhat-developer/vscode-java/issues/671#issuecomment-477379761

Since the .settings folder is created in the Java project, just open the org.eclipse.jdt.core.prefs file in it and add "org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures = enabled". .. 2019-11-08_00h05_59.png

I tried what would happen if I didn't use Maven, and I was able to run it without any errors. If you look closely, it was running with --enable-preview. 2019-11-08_00h46_20.png

It seems to be specified by Debugger for Java in the Java Extension Pack? I wonder.

I searched for the code on Github and found it below.

https://github.com/microsoft/vscode-java-debug/blob/master/src/configurationProvider.ts#L220

 // Auto add '--enable-preview' vmArgs if the java project enables COMPILER_PB_ENABLE_PREVIEW_FEATURES flag.
if (await lsPlugin.detectPreviewFlag(config.mainClass, config.projectName)) {
    config.vmArgs = (config.vmArgs || "") + " --enable-preview";
}

It seemed to be controlled by the COMPILER_PB_ENABLE_PREVIEW_FEATURES flag, and the flags were: The default seems to be enabled. (Is it correct?

https://github.com/microsoft/vscode-java-debug/blob/master/src/languageServerPlugin.ts#L76

const COMPILER_PB_ENABLE_PREVIEW_FEATURES: string = "org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures";
export async function detectPreviewFlag(className: string, projectName: string): Promise<boolean> {
    const expectedOptions = {
        [COMPILER_PB_ENABLE_PREVIEW_FEATURES]: "enabled",
    };
    return checkProjectSettings(className, projectName, true, expectedOptions);
}

Lastly, as an aside, when I saw @ bitter_fox's demo at the Oracle Code One 2019 Report Meeting that I attended the other day, I thought "Oh" is Text. The blank on the first line of Blocks was determined by the closing position at the end. I tried it and it worked. It was sober but something impressive.

2019-11-08_00h55_40.png

Recommended Posts

Add --enable-preview option in Java in Visual Studio Code
Java in Visual Studio Code
[Mac] Install Java in Visual Studio Code
[Mac] Install Java in Visual Studio Code (VS Code)
Java.home cannot be set in visual studio code.
Try remote debugging of Java with Remote Containers in Visual Studio Code Insiders
Getting started with Java programs using Visual Studio Code
I couldn't type Japanese in Ubuntu20.04 + Visual Studio Code
Output settings to debug console in Visual Studio Code
Why can I develop Java with Visual Studio Code?
Build Java program development environment with Visual Studio Code
Write Java8-like code in Java8
Build WebAPP development environment with Java + Spring with Visual Studio Code
Use PlantUML with Visual Studio Code
Guess the character code in Java
Java Spring environment in vs Code
What I learned from doing Java work with Visual Studio Code
A record of setting up a Java development environment with Visual Studio Code
Ruby on Rails in Visual Studio Codespaces
Java (add2)
Java (add)
All same hash code string in Java
Add footnotes to Word documents in Java
Call Visual Recognition in Watson Java SDK
Java to C and C to Java in Android Studio
Add SameSite attribute to cookie in Java
Experience .NET 5 with Docker and Visual Studio Code
Fastest installation of Visual Studio Code on Ubuntu
Technology for reading Java source code in Eclipse
Static code analysis with Checkstyle in Java + Gradle
Code to escape a JSON string in Java
Try using Sourcetrail (win version) in Java code
Try using Sourcetrail (macOS version) in Java code
Add, read, and delete Excel comments in Java
[AtCoder Problem-ABC001] C-Do wind observation in Java [Code]
[Java beginner's anguish] Hard-to-test code implemented in Junit
I tried "Visual Studio Code Installer for Java" which can create Java development environment immediately
Script Java code
Java code TIPS
Partization in Java
Java sample code 02
Java sample code 03
Changes in Java 11
Rock-paper-scissors in Java
Java sample code 04
Java sample code 01
Java character code
Pi in Java
FizzBuzz in Java
Installing Visual Studio Code on Ubuntu 20.04 (automatic update support)
Sample code to convert List to List <String> in Java Stream
Try to quit Eclipse and switch to Visual Studio Code
Do not write if (isAdmin == true) code in Java
Java11: Run Java code in a single file as is
Differences in code when using the length system in Java
[Oracle Cloud] Create a development environment for OCI Java SDK (Visual Studio Code, Maven, CentOS)