neoclide / coc-java

Java extension for coc.nvim
Eclipse Public License 1.0
453 stars 39 forks source link

Only one workspace across multiple projects #260

Open cutefish opened 1 year ago

cutefish commented 1 year ago

Hi,

Recently I noticed that only one workspace is opened for all my projects. I can see that I had different workspace before, and I am not sure when this issue starts. From the server log obtained with CocCommand java.open.serverLog. I got the following message:

!SESSION 2023-07-01 11:17:30.257 -----------------------------------------------
eclipse.buildId=unknown
java.version=20.0.1
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_AU
Command-line arguments:  -data /home/xiaoy/.config/coc/extensions/coc-java-data/jdt_ws

That is, it is directing to the workspace directory jdt_ws which is the same for all my projects. I think previously I have seen other directories with project names appended after jdt_ws.

I don't think I did anything special. Here is my coc-settings.json

{
  "coc.preferences.formatOnSaveFiletypes": [
  ],

  "_java.trace.server" : "verbose",
  "java.import.gradle.enabled" : false,

  "java.format.settings.url" :
  "/scratch/baox/setup/nvim/codestyle-eclipse-java.xml",

  "java.compile.nullAnalysis.mode": "disabled",

  "list.nextKeymap" : "<C-n>",
  "list.previousKeymap" : "<C-p>",

  "list.maxHeight" : 20,
  "list.maxPreviewHeight" : 24,

  "java.completion.importOrder" : ["java", "javax", "oracle", "com.oracle", "com", "org"],

  "java.jdt.ls.vmargs" : "-Xmx2G",
}

What did I do wrong?

cutefish commented 1 year ago

Perhaps I should give more context to my issue.

Recently I have been encountering the following error message whenever I open one of my projects.

[coc.nvim]: Unhandled response error -32097 from language server: Pending response rejected since connection got disposed                                                                                          
Unhandled response error -32097 from language server: Pending response rejected since connection got disposed                                                                                                      
Unhandled response error -32097 from language server: Pending response rejected since connection got disposed                                                                                                      
Exception in PromiseRejectCallback:                                                                                                                                                                                
node:internal/process/promises:144                                                                                                                                                                                 
function unhandledRejection(promise, reason) {                                                                                                                                                                     
RangeError: Maximum call stack size exceeded                                                                                                                                                                       
Exception in PromiseRejectCallback:                                                                                                                                                                                
/home/xiaoy/.local/share/nvim/plugged/coc.nvim/build/index.js:244                          

The issue goes away if I clear the workspace with CocCommand java.clean.workspace. It seems there are two issues with the first being the server rejection and second the call stack size issue. I suspect that the server rejection is the cause and the call stack size issue is a secondary effect. Therefore, I checked the server log which shows an exception stack:

!ENTRY org.eclipse.osgi 4 0 2023-07-01 10:26:13.445
!MESSAGE Application error
!STACK 1
org.eclipse.core.runtime.CoreException: Plug-in org.eclipse.jdt.ls.core was unable to load class org.eclipse.jdt.ls.core.internal.LanguageServerApplication.
    at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.throwException(RegistryStrategyOSGI.java:212)
    ...
Caused by: java.lang.ClassNotFoundException: An error occurred while automatically activating bundle org.eclipse.jdt.ls.core (51).
    at org.eclipse.osgi.internal.hooks.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:126)
    ...
Caused by: org.osgi.framework.BundleException: Error starting module. osgi.identity; type="osgi.bundle"; version:Version="1.19.0.202301170526"; osgi.identity="org.eclipse.jdt.ls.core"; singleton:="true" [id=51]
    at org.eclipse.osgi.container.Module.doStart(Module.java:614)
    ...
Caused by: java.lang.NoClassDefFoundError: org/eclipse/jdt/core/WorkingCopyOwner
    at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
    ...
Caused by: java.lang.ClassNotFoundException: An error occurred while automatically activating bundle org.eclipse.jdt.core (44).
    at org.eclipse.osgi.internal.hooks.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:126)
    ...
Caused by: org.osgi.framework.BundleException: Error starting module. osgi.identity; type="osgi.bundle"; version:Version="3.33.0.v20221214-1453"; osgi.identity="org.eclipse.jdt.core"; singleton:="true" [id=44]
    at org.eclipse.osgi.container.Module.doStart(Module.java:614)
    ...
Caused by: java.lang.NoClassDefFoundError: org/eclipse/core/resources/IWorkspaceRunnable
    at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
    ...
Caused by: java.lang.ClassNotFoundException: An error occurred while automatically activating bundle org.eclipse.core.resources (26).
    at org.eclipse.osgi.internal.hooks.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:126)
    ...
Caused by: org.osgi.framework.BundleException: Exception in org.eclipse.core.resources.ResourcesPlugin.start() of bundle org.eclipse.core.resources.
    at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:839)
    ...
Caused by: org.eclipse.core.internal.dtree.ObjectNotFoundException: Tree element '/httpperf' not found.
    at org.eclipse.core.internal.dtree.AbstractDataTree.handleNotFound(AbstractDataTree.java:178)
    ...

At the bottom of the stack is a complaint for a tree element not found where the name of the element is from another of my project. This leads me to suspect that the workspace are shared across all my projects.

Please let me know what I should do further to debug this issue. Thanks.

liuwei031015 commented 1 year ago

I also encountered similar problems. Opening an unrelated file outside the project directory will also perform a Gradle sync.

chemzqm commented 1 year ago

Workspace folders are resolved from opened files, see :h coc-workspace-folders