coc-java
coc-java copied to clipboard
Is there a way to enable preview mode when using JDK14?
I'm using JDK-14 for a project with preview enabled (when compiling with gradle) so I can test and leverage new feature like record for example. When I build the project all goes well, there is no problem there.
coc-java in the other hand is no picking gradle configuration that explicitly says --enable-preview so I have this error [Java 4195409] [E] The preview feature Records is only available with source level 15 and above .
Is there any way to tell explicitly JDTLS to enable preview mode for the java version I'm using?
Don't know if jdt.js support that.
My workaround is to set org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=enabled in the config file $PROJECT_HOME$/.settings/org.eclipse.jdt.core.prefs . coc and jdt work together smoothly with this config.
Just in case it's useful for others, I've tried with java 18 and JEP 420, and it isn't working for me. Preview is enabled and it works with Gradle, but it reports errors in NeoVim
2022-11-15T20:44:20.532 INFO (pid:17540) [extension:coc-java] - Starting Java server with: /Users/arodriguez/.sdkman/candidates/java/18.0.2-amzn/bin/java --add-modules=ALL-SYSTEM --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED -Declipse.application=org.eclipse.jdt.ls.core.id1 -Dosgi.bundles.defaultStartLevel=4 -Declipse.product=org.eclipse.jdt.ls.core.product -Dfile.encoding=utf-8 --enable-preview -jar /Users/arodriguez/.config/coc/extensions/coc-java-data/server/plugins/org.eclipse.equinox.launcher_1.6.400.v20210924-0641.jar -configuration /Users/arodriguez/.config/coc/extensions/coc-java-data/server/config_mac -data /Users/arodriguez/.config/coc/extensions/coc-java-data/jdt_ws_e878dfd45c90b8f65ad10aadefe68910
.settings/org.eclipse.buildship.core.prefs
arguments=--init-script /Users/arodriguez/.config/coc/extensions/coc-java-data/server/config_mac/org.eclipse.osgi/50/0/.cp/gradle/init/init.gradle
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(LOCAL_INSTALLATION(/Users/arodriguez/.sdkman/candidates/gradle/current))
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=/Users/arodriguez/.sdkman/candidates/java/18.0.2-amzn
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=enabled
coc-settings.json
"java.jdt.ls.vmargs": "--enable-preview",
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=enabled
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
reportPreviewFeatures could be set to ignore, or jdt will report a warning.
and I've encountered JEP420 related issues several times(IIRC, every time after I updated the jdt)
Since jdt was updated, I always deleted all jdt_ws_..... directory in my $HOME/.config/coc/extensions/coc-java-data, so the pattern mathing features works again in my java porjects. It seems that new versions of jdt doesn't keep compatibilities with old data when preview features are enabled.
Just like the report you pasted out ,
/Users/arodriguez/.config/coc/extensions/coc-java-data/jdt_ws_e878dfd45c90b8f65ad10aadefe68910
That's the directory.
Open and load the java project, make sure coc-java is working -> :CocCommand java.updateLanguageServer -> :q -> delete jdt_ws_directories -> open that java project again. This is how I resolve the issue. Hope this helps.
Thanks, kandu. It didn't work for me but it could be because of https://github.com/neoclide/coc-java/issues/227. I will try again once that issue is fixed.
Added a section for compile options to Readme https://github.com/neoclide/coc-java/blob/master/Readme.md#compiler-warnings