Skip to content
This repository has been archived by the owner on Jun 10, 2020. It is now read-only.

Javadoc #76

Open
realark opened this issue Nov 4, 2018 · 2 comments
Open

Javadoc #76

realark opened this issue Nov 4, 2018 · 2 comments

Comments

@realark
Copy link
Contributor

realark commented Nov 4, 2018

Hello, I'm interested in adding a feature to show javadoc.

  • Is this a good idea? Should I start with a simpler feature to get my feet wet, is this already being worked on (etc)?
  • Any tips for getting started with development (Other than Contirbuting) ?
    • What are the critical intellij/lsp functions to consider?
@Ruin0x11
Copy link
Owner

Ruin0x11 commented Nov 5, 2018

Hello.

It's perfectly fine to implement. Parts of the relevant classes needed are used already also, so I have a good idea of how it would be done.

The main places that LSP can request documentation information are textDocument/signatureHelp and textDocument/completion. In the case of completion, it is possible to use the completionItem/resolve request (which is implemented in CompletionItemResolveCommand) to calculate additional information for a single selected completion item, including documentation.

The primary place for Javadoc generation seems to be JavaDocInfoGenerator. A modified version of this class is used to generate the signature on hover information, OneLineJavaDocInfoGenerator. Another class handles finding documentation for the element at point, in HoverDocumentationProvider, modified from IntelliJ's JavaDocumentationProvider.

Basically, I think the process for adding the Javadoc information would be to take advantage of these classes using AbstractDocumentationProvider.generateDoc to generate the documentation string when a completionItem/resolve request comes in, then attach it to an instance of LSP's SignatureInformation and return it in the response. An example of this can be found in HoverCommand, which handles the textDocument/hover request. The cache for recently created completion items (PreviousCompletionCacheService) contains LookupItems which can be resolved to the appropriate PsiElement to use with generateDoc, so it should be usable there. The same can be done when a textDocument/signatureHelp request comes in.

The documentation string might need modification to remove IntelliJ's XML markup, however. This could be accomplished by duplicating the class, or stripping the markup like in HoverDocumentationProviderKt.

Also, the textDocument/signatureHelp request would need to be implemented to use it for showing documentation. It can be added as an override inside MyTextDocumentService. Correspondingly, a
subclass of DocumentCommand to handle the request logic should be created. There are many examples in the com.ruin.lsp.commands.document package. Of course, the easier part would probably be augmenting completionItem/resolve first.

I hope this helps.

@realark
Copy link
Contributor Author

realark commented Nov 9, 2018

Thank you! That's extremely helpful and enough to keep me busy.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants