Search code examples
javavisual-studio-codejavadoc

How to view Java standard library documentation popup in Visual Studio Code with OpenJDK 11 on Ubuntu 21.04?


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


Solution

  • 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.