sts4 icon indicating copy to clipboard operation
sts4 copied to clipboard

Restart the JDT LS without restarting the Spring Boot LS

Open XiaoYuhao opened this issue 3 years ago • 3 comments

I am trying to develop a java vscode extension which restarts eclipse JDT language server without reloading the vscode window. However, after some investigation, I found that there are some interactions between the Spring Boot LS and the JDT LS.

I am wondering if restarting the JDT LS without reloading the vscode window (actually without restarting the Spring Boot LS) can work correctly?

Appreciate a lot if you could provide some insights. Thank you for the great project.

XiaoYuhao avatar Jun 23 '22 03:06 XiaoYuhao

Interactions between Boot LS and JDT LS are stateless except one message: add/remove classpath listener. This registers a "callback" in JDT LS to execute once projects and/or classpath of a project has changed. These listeners are registered at the initialization phase of Boot LS.

Therefore if JDT LS is restarted without Boot LS the listeners are gone. Consequently, any changes to projects classpath or addition/removal of the projects won't be tracked which would result in Boot LS features not working for newly added projects or working for projects that were removed or not working correctly for projects with changed classpath.

There is, however, a command that we've added in the past sts.vscode-spring-boot.enableClasspathListening that takes a boolean parameter to enable/disable classpath listener. The command was added to handle JDT LS standard, hybrid and syntax modes. I'd try executing this command with false parameter before re-starting JDT LS and then once JDT LS is ready executing the same command with true parameter. Hope this works :-)

BoykoAlex avatar Jun 24 '22 15:06 BoykoAlex

@BoykoAlex Thank you for providing comments. I still have some questions I want to get clarified.

  1. I'd try executing this command with false parameter before re-starting JDT LS and then once JDT LS is ready executing the same command with true parameter. Do you mean that the add/remove classpath listener will be re-registered after restarting JDT LS by executing this command with true parameter?
  2. Is there any test case where I can verify the correctness of Boot LS after restarting JDT LS?

XiaoYuhao avatar Jun 30 '22 06:06 XiaoYuhao

@XiaoYuhao Sorry for the late reply - was away for a couple of days.

  1. Yes. Before JDT LS is shut down execute the command with false parameter to remove classpath listener (this is sort of optional). However, once the JDT LS is started and is in "ready" state the command needs to be executed with true parameter to add the classpath listener.
  2. I'd try testing like follows:
  • Create a simple spring boot project called with spring web starter (no spring cloud dependencies)
  • Open src/main/resources/application.properties file. Type loadbalancer and invoke content assist at the end of the work - no proposals
  • Restart JDT LS
  • Add Cloud Bootstrap starter. Then in Maven section of the explorer view expand dependencies and refresh them (i found that adding a starter does not refresh maven dependencies and i had to refresh them manually). You should see spring-cloud-starter in the dependencies
  • Invoke content assist again in application.properties right after loadbalancer - proposals such as spring.cloud.loadbalancer.* should be seen

If this works it means classpath listener is added successfully after restart of JDT LS.

BoykoAlex avatar Jul 06 '22 14:07 BoykoAlex