3

A similar question was asked for Eclipse: Add Java Docs in Eclipse working on OpenJDK

I found /usr/lib/jvm/java-11-openjdk-amd64/lib/src.zip on my system.

Building and runing a source file works. Documentation is shown for dependencies loaded via Maven. The documentation for the Java standard library is missing.

Examples:

hovering over

System.out.println("test");

shows

void java.io.PrintStream.println(String x)

I would like to see the javadoc here.

It is working with:

new DefaultCamelContext();

It shows:

org.apache.camel.impl.DefaultCamelContext.DefaultCamelContext()

Creates the ModelCamelContext using org.apache.camel.support.DefaultRegistry as registry.

Use one of the other constructors to force use an explicit registry.

Edit: Relevant Installed Visual Studio Code Extensions are:

  • Language Support for Java(TM) by Red Hat
  • Debugger for Java
  • Java Test Runner
  • Maven for Java
  • Project Manager for Java
  • Visual Studio IntelliCode

These are installed via the official Java Extension Pack from Microsoft.

edit2: my user settings.json

{
    "telemetry.enableTelemetry": false,
    "telemetry.enableCrashReporter": false,
    "editor.fontFamily": "'Ubuntu Mono', 'Droid Sans Mono', 'monospace', monospace, 'Droid Sans Fallback'",
    "files.autoSave": "onFocusChange",
    "window.zoomLevel": 3,
    "editor.wordWrap": "bounded",
    "yaml.schemas": {
        "file:///toc.schema.json": "/toc\\.yml/i"
    },
    "window.menuBarVisibility": "default",
    "rust-analyzer.checkOnSave.command": "clippy",
    "editor.minimap.enabled": false,
    "editor.cursorBlinking": "solid",
    "rust-analyzer.checkOnSave.enable": false,
    "explorer.sortOrder": "mixed",
    "rust-analyzer.lens.methodReferences": true,
    "rust-analyzer.lens.references": true,
    "rust-analyzer.lruCapacity": 512,
    "workbench.colorTheme": "Default Dark+",
    "editor.suggestSelection": "first",
    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "files.exclude": {
        "**/.classpath": true,
        "**/.project": true,
        "**/.settings": true,
        "**/.factorypath": true
    },
    "java.home": "/usr/lib/jvm/java-11-openjdk-amd64",
    "java.configuration.runtimes": [
        {
          "name": "JavaSE-11",
          "path": "/usr/lib/jvm/java-11-openjdk-amd64",
          "default": true
        }
    ]
}

my workspace settings.json is empty

nuiun
  • 764
  • 8
  • 19

3 Answers3

3

When i hover over the println(), the description is as the same as the comment you can get by Ctrl+Clicking the method:

enter image description here

Java extension can't detect and show the documentation if they don't even exist in jdk at all. You can try in your project and see if the java you installed has documentation.

Could you try to install the openjdk-src or openjdk-doc package? See OpenJDK.

OR install another java version and set it as java.home in vscode to see if this question still exists.

Molly Wang-MSFT
  • 7,943
  • 2
  • 9
  • 22
  • 3
    installing `openjdk-11-doc` and `openjdk-11-source` worked. I think I had installed `openjdk-11-doc` already. So my guess is `openjdk-11-source` was missing. The screenshot was a good hint. When I ctrl+click `println()` now I see the javadoc, which was missing before I installed `openjdk-11-source`. Thankyou – nuiun Jul 16 '21 at 10:17
  • @nuiun. Glad to know your question is solved. Happy coding:) – Molly Wang-MSFT Jul 19 '21 at 01:03
  • @Molly Wang-MSFT. same problem, how do install the openjdk-src or openjdk-doc package? – UN..D Nov 27 '22 at 09:59
1

After searching,I found the the problem was about the configuring of user settings.json file

  Add the same path as JAVA_HOME in the "java.jdt.ls.java.home" config

Now, I can see the documents but it show at the top

// Source code is unavailable, and was generated by the Fernflower decompiler.

Also it didn't show information when hover on method ...

Next, try to install the openjdk-src or openjdk-doc package as mention by @Molly Wang-MSFT.

For more information check Java in Visual Studio Code


Use below setting to handle not existed jar file locally (ex:Spring documentation):

You can enable the user setting.json "java.maven.downloadSources":true,

each time you opened a class file, if the source jar does not exist locally, the extension will trigger a download task for that source jar.

UN..D
  • 543
  • 5
  • 15
  • That did the trick for me. Setting java.jdt.ls.java.home in settings.json and installing both openjdk-17-doc and openjdk-17-source packages in my system. Notice it is also needed to clean the vscode workspace afterwards to reload the new configurations (ctrl+shift+p then "Clean Java Language Server Workspace"). – Leandro 86 Apr 05 '23 at 18:14
0

You could try using this extension pack (it contains the extension Language Support for Java(TM) by Red Hat that gives the information you're looking for when hovering over Java code):

enter image description here

Make sure to also have tooltips enabled. You can read about enabling them here.

Rusu Dinu
  • 477
  • 2
  • 5
  • 16
  • 1
    To be more specific, it's [Language Support for Java(TM) by Red Hat](https://marketplace.visualstudio.com/items?itemName=redhat.java) that provides Java Linting, Intellisense, formatting and more.. – Molly Wang-MSFT Jul 14 '21 at 09:15
  • I installed the mentioned https://marketplace.visualstudio.com/items?itemName=redhat.java extension already. Thankyou for the links, I will check if I find something there. – nuiun Jul 14 '21 at 11:41
  • @Dinu: if I may ask: what operating system are you running? Are you running OracleJDK or OpenJDK? – nuiun Jul 14 '21 at 11:52
  • @nuiun. I'm using openjdk11 in Windows, with java extension pack installed, javadoc can be shown when hovering over the code. Can you share your user and worksapce settings.json for me to check if you turn off some intellisense settings? – Molly Wang-MSFT Jul 15 '21 at 02:55
  • @nuiun windows 10, oraclejdk 15 – Rusu Dinu Jul 15 '21 at 12:06
  • @MollyWang-MSFT I edited the request. It shows a dump of my user settings.yml now. – nuiun Jul 16 '21 at 07:44
  • @nuiun. Please Install another java version and set it as `java.home` in vscode to see if this question still exists. – Molly Wang-MSFT Jul 16 '21 at 08:03