eclipse.jdt.ls icon indicating copy to clipboard operation
eclipse.jdt.ls copied to clipboard

Java LS with vscode-pde rebuilds workspace for every restart

Open snjeza opened this issue 3 years ago • 7 comments

Fixes #1960

Both, VS Code PDE and Java LS set default JVMs. See

  • https://git.eclipse.org/c/pde/eclipse.pde.ui.git/tree/ui/org.eclipse.pde.core/src/org/eclipse/pde/core/target/LoadTargetDefinitionJob.java?id=2ece9c75272658af52e62ec8eb4e759ee8ed916f&h=master#n227
  • https://github.com/eclipse/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/JVMConfigurator.java#L98
  • https://github.com/eclipse/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/JVMConfigurator.java#L186

If those JVMs are different, Java LS will update all projects. The issue can't be reproduced when starting VS Code with JDK 11 and without java.configuration.runtimes.

The PR adds the java.ls.doNotSetDefaultJVM property. Java LS won't set a default JVM if it is started with -Djava.ls.doNotSetDefaultJVM=true.

Test vsix: https://github.com/snjeza/vscode-test/raw/master/java-1.2.4.vsix Test project: https://github.com/eclipse/eclipse.jdt.ls Test vmargs:

"java.jdt.ls.vmargs": "-Djava.ls.doNotSetDefaultJVM=true <YOUR_VMARGS>",

Signed-off-by: Snjezana Peco [email protected]

snjeza avatar Dec 06 '21 01:12 snjeza

If those JVMs are different, Java LS will update all projects. The issue can't be reproduced when starting VS Code with JDK 11 and without java.configuration.runtimes.

The reason is probably from the following code. It will bring some unnecessary project update event if java.configuration.runtimes explicitly sets a different JDK as default.

https://github.com/eclipse/eclipse.jdt.ls/blob/791f30ed63f9960d5ad7dc2e9ba3b9e203cf2b9a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/JVMConfigurator.java#L306-L308

Reproduce steps:

  • set java.home is set JDK 11
  • add a JDK 17 to java.configuration.runtimes, and set its default to true.
  • reopen vscode on a Java project (e.g. eclipse.jdt.ls), you will see the log like "!MESSAGE defaultVMInstallChanged -> force update of org.eclipse.jdt.ls.core".

testforstephen avatar Dec 10 '21 07:12 testforstephen

The reason is probably from the following code. It will bring some unnecessary project update event if java.configuration.runtimes explicitly sets a different JDK as default.

Right! The -Djava.ls.doNotSetDefaultJVM=true fixes it.

snjeza avatar Dec 10 '21 14:12 snjeza

How would this work on the client side ? Would the client need to set -Djava.ls.doNotSetDefaultJVM=true if they don't detect a setting for java.configuration.runtimes where default: true is used ? Is there any way to fix this on the language server side by addressing the TODO comment ?

rgrunber avatar Apr 30 '22 04:04 rgrunber

How would this work on the client side ? Would the client need to set -Djava.ls.doNotSetDefaultJVM=true if they don't detect a setting for java.configuration.runtimes where default: true is used ? Is there any way to fix this on the language server side by addressing the TODO comment ?

It could be done in the Eclipse PDE support extension.

snjeza avatar Apr 30 '22 16:04 snjeza

@testforstephen , can this be used to avoid having vscode-pde rebuilding the workspace unnecessarily ? How would vscode-pde set this property, since it only contributes to JDT-LS via bundles, and at that point it's probably too late to set the system property.

rgrunber avatar Sep 23 '22 18:09 rgrunber

@testforstephen , can this be used to avoid having vscode-pde rebuilding the workspace unnecessarily ? How would vscode-pde set this property, since it only contributes to JDT-LS via bundles, and at that point it's probably too late to set the system property.

Yes, vscode-pde doesn't have a good way to specify such property. We need a better approach that does not depends on system property to fix this.

testforstephen avatar Sep 26 '22 05:09 testforstephen

Ok, so then we can't merge this PR in the current form.

What we really need is a nice way for JDT-LS to detect whether a bundle extension wants to handle setting the runtime, and if so, simply avoid setting it.

rgrunber avatar Sep 26 '22 16:09 rgrunber