简体   繁体   中英

How to show Javadoc of a imported library when hovering on its methods and classes?

As described in the title. We were currently using JSFML and Swing to develop a project, where I would like to view the Javadoc of JSFML in VSCode. However, when I tried to hover to show Javadoc it doesn't but throws me only a simple line.

For example: I built a renderWindow by using one of JSFML's package, graphic (with class RenderWindow ), and try to hover. It shows me this:

org.jsfml.graphics.RenderWindow.RenderWindow(VideoMode arg0, String arg1)

Instead of Javadoc of it. When I went into the definition, instead of Javadoc I saw such a comment at the head of its class file:

 // Failed to get sources. Instead, stub sources have been generated by the disassembler.
 // Implementation of methods is unavailable.

How can I see the Javadoc of it in VSCode? Or I actually was not allowed to since it's restricted(?)

Link for JSFML here if it helps:

That's because the jar package which is downloaded from official website doesn't include the description.

Like you can see, when we hover over the function println and ctrl+click to see its class, the docstrings and parameter information are from the comments in class: 在此处输入图像描述

However, RenderWindow.class doesn't have this kind of comments, so java extension will only show its package structure: 在此处输入图像描述

It's not related to VS Code or Java extension but the jsfml.jar itself, you can view JSFML javadoc to get more detailed information.

Molly's answer explains why the javadoc is not available for your JAR.

If JSFML or any other Java dependency you use has a source jar, VS Code can use it so you can see the source and its Javadoc just like the JDK. The steps to get it visible in VS Code are:

Steps to see Javadoc in VS Code with Attach Source

  1. Get the source JAR of the dependency (eg download manually, using Maven, ...)
  2. In VS Code, click into the class you want to see Javadoc for (eg org.jsfml.graphics.RenderWindow.RenderWindow )
  3. In the file that opens with the message Failed to get sources. Instead, stub sources have been generated by the disassembler... Failed to get sources. Instead, stub sources have been generated by the disassembler... , right/alt click to open the context menu and select Attach Source .
  4. Select the source JAR that you got earlier.
  5. Javadoc and source of the dependency will now be visible in VS Code and Javadoc will display on hover.

Screenshots of steps

Attach Source in context menu

Select source jar

Acknowledgement

This solution was originally proposed in https://github.com/redhat-developer/vscode-java/issues/1855#issuecomment-823142835 on a similar issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM