eclipse-jdtls / eclipse.jdt.ls

Java language server
1.8k stars 400 forks source link

OpenJDK 11 javadoc not returned on hover #1006

Closed bgx90 closed 5 years ago

bgx90 commented 5 years ago

I am running Debian testing with OpenJDK 11. I am using Neovim v0.3.4. Lately, jdt.ls has not been returning javadoc from the OpenJDK 11 doc package in hover responses. For example, if I hover on the keyword String, I do not get the javadoc for String. Instead I get this: image I had it working with snapshot jdt-language-server-0.36.0-201903201910 and neoclide/coc-java as my client for a while and it just suddenly stopped working. The problem seemed to be that I had set JAVA_HOME for maven and I was able to get snapshot jdt-language-server-0.36.1-201904020132 to send javadoc by explicitly configuring the path to the jdk in coc's settings (even though it was the same path as JAVA_HOME). However, jdt.ls has stopped sending the jdk javadoc again and I have not been able to get it to work again. I have tried the most recent snapshot (jdt-language-server-0.37.0-201904162228) but it does not send the jdk javadoc either. To rule out coc as the problem, I also tried using prabirshrestha/vim-lsp as my client and I still had the same problem. Here is a trace I get from coc:

[Trace - 3:45:08 PM] Sending request 'textDocument/hover - (5)'.
Params: {
    "textDocument": {
        "uri": "file:///home/user/udemy/maven/mb2g-lombok/src/main/java/guru/springframework/model/User.java"
    },
    "position": {
        "line": 12,
        "character": 14
    }
}

[Trace - 3:45:08 PM] Received response 'textDocument/hover - (5)' in 56ms.
Result: {
    "contents": {
        "language": "java",
        "value": "java.lang.String"
    }
}

The bug report I made to neoclide/coc-java concerning this issue can be found here. I have closed that issue since this seems to be a problem between jdt.ls and OpenJDK 11 on Debian and not an issue with my lsp client.

fbricon commented 5 years ago

Can you try with VS Code?

bgx90 commented 5 years ago

I installed VS Code and the Language Support fo Java by Red Hat extension. I still don't get JDK javadoc when I hover.

Hovering on String: image

Hovering on System.out.println(): image

Output from dpkg-query showing that the doc package is installed:

$ dpkg -l openjdk-11-*
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                          Version      Architecture Description
+++-=============================-============-============-==================================================
un  openjdk-11-demo               <none>       <none>       (no description available)
ii  openjdk-11-doc                11.0.3+1-1   all          OpenJDK Development Kit (JDK) documentation
ii  openjdk-11-jdk:amd64          11.0.3+1-1   amd64        OpenJDK Development Kit (JDK)
ii  openjdk-11-jdk-headless:amd64 11.0.3+1-1   amd64        OpenJDK Development Kit (JDK) (headless)
ii  openjdk-11-jre:amd64          11.0.3+1-1   amd64        OpenJDK Java runtime, using Hotspot JIT
ii  openjdk-11-jre-headless:amd64 11.0.3+1-1   amd64        OpenJDK Java runtime, using Hotspot JIT (headless)
un  openjdk-11-source             <none>       <none>       (no description available)
fbricon commented 5 years ago

That's odd. jdt.ls generally supports javadoc attached to libraries. But I don't remember having tested javadoc attached to a JDK, usually people simply add the JDK sources instead. @bgx90 I'm not a linux person, so it's unclear to me whether you have the sources installed or not. Please check if installing the JDK sources give you a better result.

@snjeza is this (attached openjdk javadoc) something you could check?

snjeza commented 5 years ago

I can reproduce the issue on Fedora 29. It is fixed by installing the JDK sources (java-11-openjdk-src). I have tested VS Code and Eclipse.

fbricon commented 5 years ago

My understanding is JDT computes a default remote Javadoc url for at least Oracle JDK, but I don't know how it handles local javadoc or other JDKs. There might be room for some improvement at the JDT level.

snjeza commented 5 years ago

JDT searches https://docs.oracle.com/en/java/javase/11/docs/api/java/lang/String.html instead of https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html.

fbricon commented 5 years ago

@snjeza I think there are 2 issues to address then:

Can you please open or link to upstream BZ tickets?

snjeza commented 5 years ago

Related BZ ticket - https://bugs.eclipse.org/bugs/show_bug.cgi?id=546945

bgx90 commented 5 years ago

I still have no success getting the javadoc to show up. I tried installing the openjdk 11 sources package as @fbricon and @snjeza suggested, but I still do not see the javadoc info in vscode or in neovim (using coc and coc-java). I have tried standalone java files and java files inside a maven project. When testing with vscode, I use File > Open Folder to open the root of my maven project and then open a java file to test the hover; I am not familiar with vscode, so please let me know if I am using it correctly for this use case.

Trying hover in maven project using vscode: image

dpkg output showing openjdk11 jdk, javadocs, and sources are installed (the letter i in the second column means installed):

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                          Version      Architecture Description
+++-=============================-============-============-====================
un  openjdk-11-demo               <none>       <none>       (no description avai
ii  openjdk-11-doc                11.0.3+1-1   all          OpenJDK Development 
ii  openjdk-11-jdk:amd64          11.0.3+1-1   amd64        OpenJDK Development 
ii  openjdk-11-jdk-headless:amd64 11.0.3+1-1   amd64        OpenJDK Development 
ii  openjdk-11-jre:amd64          11.0.3+1-1   amd64        OpenJDK Java runtime
ii  openjdk-11-jre-headless:amd64 11.0.3+1-1   amd64        OpenJDK Java runtime
ii  openjdk-11-source             11.0.3+1-1   all          OpenJDK Development
fbricon commented 5 years ago

I'm not sure but there's a chance you might need to clean up (i.e delete) your server workspace 1st. It's the value of the -data argument you use to launch jdt.ls. In VS Code, simply execute the "Clean the Java language server workspace".

bgx90 commented 5 years ago

I ran the "Clean the Java language server workspace" command and then clicked the "Restart and Delete" button, but I still see no javadoc.

snjeza commented 5 years ago

Does the $JAVA_HOME/lib/src.zip file exist?

bgx90 commented 5 years ago

On Debian, the openjdk source package installs the src.zip file to /usr/lib/jvm/openjdk-11/lib/src.zip. The files contained are also extracted into /usr/share/doc/openjdk-11-source.

snjeza commented 5 years ago

Could you try to set the following:

"java.home": "/usr/lib/jvm/openjdk-11/",

and run "Clean the Java language server workspace"?

bgx90 commented 5 years ago

That path causes an error since there is no jvm there. I set the path to the jdk installation (which is also set in my JAVA_HOME environment variable) "java.home": "/usr/lib/jvm/java-11-openjdk-amd64". I then ran "Clean the Java language server workspace". I still do not see any javadoc.

snjeza commented 5 years ago

Could you try to run the following:

ln -s /usr/lib/jvm/openjdk-11/lib/src.zip /usr/lib/jvm/java-11-openjdk-amd64/lib/src.zip
bgx90 commented 5 years ago

You just led me to the problem. /usr/lib/jvm/java-11-openjdk-amd64/lib/src.zip already existed, but it was a broken link. It was incorrectly set to ../openjdk-11/src.zip when it should have been set to ../openjdk-11/lib/src.zip. Javadoc started working after I fixed the link. I will be filing a bug report with the Debian package maintainer. Thank you @snjeza and @fbricon so much for your help.

bgx90 commented 5 years ago

Debian bug report: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=928369

Yanpas commented 5 years ago

Same issue in ubuntu. Fixes with sudo ln -fsr /usr/lib/jvm/openjdk-11/lib/src.zip /usr/lib/jvm/java-11-openjdk-amd64/src.zip. Need to install openjdk-11-source as well

muggell commented 5 years ago

You just led me to the problem. /usr/lib/jvm/java-11-openjdk-amd64/lib/src.zip already existed, but it was a broken link. It was incorrectly set to ../openjdk-11/src.zip when it should have been set to ../openjdk-11/lib/src.zip. Javadoc started working after I fixed the link. I will be filing a bug report with the Debian package maintainer. Thank you @snjeza and @fbricon so much for your help.

Where did you correct this because I'm experiencing the same thing on my linux system. I've just done what @snjeza suggested, and it worked. But I'd like to permanently fix it. @bgx90

bgx90 commented 5 years ago

My solution was what @snjeza suggested. That is the permanent fix for the problem. The maintainer of the debian package openjdk-11-jdk-headless has responded to my bug report saying that the upcoming version of openjdk-11-jdk-headless will include the fix for the symlink, so we don't need to worry about an update to the package causing a regression.

EDIT: I assumed you meant that you fixed the symlink when you said you followed @snjeza's suggestion. I am using Debian and @snjeza is using Fedora and she was able to fix the problem by installing the openjdk src package, so maybe that is what you meant. Since the Debian packages differ from Fedora's I can't say what the cause of the issue on Fedora is. I only know that for Debian it was a broken symlink and that it will be fixed in the upcoming version.

muggell commented 5 years ago

I see! I did fix the symlink, but I'm a pretty new user of Linux, so I wasn't sure if that was a "permanent" fix of the problem in terms of future problems. I basically didn't understand what the symlink was all about. But it did fix it, and it's running properly now giving me the javadoc needed and all. But thansk a lot for the quick response. I really appreciate it.

fbricon commented 5 years ago

I am using Debian and @snjeza is using Fedora and he was able to fix the problem

@bgx90 FYI @snjeza is a lady ;-)

bgx90 commented 5 years ago

Oops, my mistake. Thanks for letting me know. I have corrected the post.

Yanpas commented 5 years ago

Reported bug in ubuntu https://bugs.launchpad.net/ubuntu/+source/openjdk-lts/+bug/1828814

STimur commented 4 years ago

Same issue in ubuntu. Fixes with sudo ln -fsr /usr/lib/jvm/openjdk-11/lib/src.zip /usr/lib/jvm/java-11-openjdk-amd64/src.zip. Need to install openjdk-11-source as well

don't fully understand why it works, but this command helped me resolve same issue in IntelliJ IDEA 2019.3.1 (Ultimate Edition) on ubuntu 18.04.3 LTS - i had no documentation for Java SE 11 when pressing Ctrl-Q

Thanks a lot!