zed icon indicating copy to clipboard operation
zed copied to clipboard

Language server error: jdtls

Open tempcoderr opened this issue 6 months ago • 4 comments

Summary

I am getting the "Language server error: jdtls" when I open Zed.

The zed.log file contains the following logs for LSP:

2025-05-31T03:03:30+05:30 INFO  [lsp] starting language server process. binary path: "/Users/username/Library/Application Support/Zed/extensions/work/java/jdtls/jdt-language-server-1.47.0-202505151856/bin/jdtls", working directory: "/Users/username/Developer/test/dsa", args: []
2025-05-31T03:03:30+05:30 INFO  [project::lsp_store] language server 2: unregistered workspace/DidChangeWatchedFiles capability with id 1612599d-6bc6-41fd-ae2b-9896939c3a7c
2025-05-31T03:03:34+05:30 ERROR [lsp] cannot read LSP message headers
2025-05-31T03:03:34+05:30 ERROR [lsp] Server reset connection for a request "initialize" id 0
2025-05-31T03:03:34+05:30 ERROR [lsp] server shut down
2025-05-31T03:03:34+05:30 ERROR [lsp] Broken pipe (os error 32)
2025-05-31T03:03:34+05:30 ERROR [project::lsp_store] Failed to start language server "jdtls": Error {
    context: "initializing server jdtls, id 1",
    source: "Server reset the connection",
}
2025-05-31T03:03:34+05:30 ERROR [project::lsp_store] server stderr: WARNING: Using incubator modules: jdk.incubator.vector
May 31, 2025 3:03:32 AM org.apache.aries.spifly.BaseActivator log
INFO: Registered provider ch.qos.logback.classic.spi.LogbackServiceProvider of service org.slf4j.spi.SLF4JServiceProvider in bundle ch.qos.logback.classic

Zed Version and System Specs

Zed: v0.188.5 (Zed) OS: macOS 15.0.1 Memory: 8 GiB Architecture: aarch64

tempcoderr avatar May 30 '25 21:05 tempcoderr

I was looking for the cause of this issue and found that manually running the same jdtls binary used by Zed does not produce any errors.

Then I added some logs in the jdtls.py script and discovered that the -data argument being passed to the executable was pointing to another directory:

/var/folders/0q/mzhf2fxn7k314sk8q_gs08rh0000gn/T/jdtls-e908389d4bbf30e8dc72dc47cdf6b45d89e8b2a0

This seems to be the issue. My Java file contains multiple classes that are not present in this temporary location, which leads to a ObjectNotFoundException. I confirmed this by inspecting the JDTLS log file at:

/private/var/folders/0q/mzhf2fxn7k314sk8q_gs08rh0000gn/T/jdtls-e908389d4bbf30e8dc72dc47cdf6b45d89e8b2a0/.metadata/.log

And got the following error log:

org.osgi.framework.BundleException: Exception in org.eclipse.core.resources.ResourcesPlugin.start() of bundle org.eclipse.core.resources.
...
Caused by: org.eclipse.core.internal.dtree.ObjectNotFoundException: Tree element '/dsa_e7012004/bin/TreeNode.class' not found.

When I modified the default data path in jdtls.py to point to my actual project directory:

parser.add_argument("-data", default="/Users/username/Developer/test/dsa/")

the JDTLS server started up correctly and worked as expected.

tempcoderr avatar May 31 '25 09:05 tempcoderr

"-data"

This is not set on the Zed side though, and never will be as Zed knows nothing about Java.

Should this issue rather belong to https://github.com/ABckh/zed-java-eclipse-jdtls or whatever the Java extension you're using?

SomeoneToIgnore avatar May 31 '25 09:05 SomeoneToIgnore

@SomeoneToIgnore I am using the following java extension https://github.com/zed-extensions/java. Also in between different Zed version the issue gets resolved by itself but after updating Zed jdtls breaks again.

tempcoderr avatar May 31 '25 10:05 tempcoderr

So, there was a version of Zed where things worked?

It would be super useful if we could pinpoint the version where things worked, https://github.com/zed-industries/zed/releases might help you to do that.

And please provide the repro steps for people with 0 Java set-up to check that.

SomeoneToIgnore avatar May 31 '25 10:05 SomeoneToIgnore

@SomeoneToIgnore I tried various Zed versions but have not been able to make JDTLS work. It seems when I updated Zed, the private folder might also have been refreshed (not sure about this though).

Also one more weird thing which I found was that if the java file which is open when I open Zed has just one class, then JDTLS works fine, but if It has multiple classes, then the JDTLS throws the error as specified above.

To do the Java set-up I would suggest the following these steps:

  1. Install the Java extension in Zed (https://github.com/zed-extensions/java)
  2. Creating a java file in any folder and create multiple classes in that java file.
  3. Verify if JDTLS works or not.

tempcoderr avatar May 31 '25 15:05 tempcoderr

I tried doing one more thing. I deleted all the JDTLS folders in the "/var/folders/0q/mzhf2fxn7k314sk8q_gs08rh0000gn/T/" path and then reopened my project in Zed, and now JDTLS is working even for the java file with multiple classes. The version and specs are same as before: Zed: v0.188.5 (Zed) OS: macOS 15.0.1 Memory: 8 GiB Architecture: aarch64

tempcoderr avatar May 31 '25 15:05 tempcoderr

@tempcoderr Glad to hear JDTLS is working (for the moment).

Can you open this as an issue on the zed-extensions/java repo if you have some way of triggering this behavior?

If you are having trouble with the automatically downloaded jdtls you might try manually installing jdtls. More information in the Zed Java Docs and in the Zed Java Readme

notpeter avatar May 31 '25 18:05 notpeter