Getting documentation from code completion popup (using Documentation Target API)

Answered

I'm working on a language plugin, and I've managed to get documentation (platform.backend.documentation.targetProvider EP) to work when pressing F1 in code, and I have gotten code completion (completion.contributor EP) to work when pressing ctrl+space in code.

But, I can't figure out what I need to do to get F1 to work from the code completion popup? 

For example, say I type I type “c”, press ctrl+space, select “class” from popup list and then press F1, then I want to be able to display documentation for the “class” keyword.

 

0
1 comment

Ok, I solved it myself. Not exactly pretty – so if someone has better ideas I'd still like the hear it – but it seems adequate. 

  1. Defined the EP platform.backend.documentation.psiTargetProvider similar to the targetProvider
  2. In my CompletionProvider's addCompletions()
    1. get project via completionParameters.getPosition().getProject()
    2. create a PsiFile with the text to lookup within suitable context with PsiFileFactory.getInstance(project).createFileFromText()
    3. feed the relevant PsiElement from that PsiFile to LookupElementBuilder.createWithSmartPointer()
0

Please sign in to leave a comment.