Provide completion from my language to another
Hello guys.
I have a code which provides references from PsiLiteral elements to the files from my custom language:
def registerReferenceProviders(registrar: PsiReferenceRegistrar) { registrar.registerReferenceProvider(PlatformPatterns.psiElement(classOf[PsiLiteral]), new PsiReferenceProvider() { def getReferencesByElement(element: PsiElement, context: ProcessingContext) = { val literal = element.asInstanceOf[PsiLiteral] literal.getValue match { case text: String => if (text != null && text.endsWith(".table")) { Array[PsiReference](new XrlDecideReference(element, new TextRange(1, text.length() - ".table".length + 1), "table")) } else Array[PsiReference]() case _ => Array[PsiReference]() } } }) }
Now I can go by Ctrl+Click from PsiLiteral elements directly to the *.table files
My question is how to add completion provider to provide completion for *.table files inside PsiLiteral elements?
I found CompletionProvider API but I don't understand how to enable it.
Thanks!
Please sign in to leave a comment.
The easiest way is to implement getVariants in your reference and return LookupElement[] from it.
If your completion might take a long time or you need some advanced stuff, you can implement CompletionContributor. Its Javadoc contains the necessary details.
Hi Peter,
Thank you wery much! I thought that contibutor can be only used inside your own custom language, because when it defiened in plugin.xml it also has "language" tag. But I found that language can be specified as "any":
I also want to ask, why literal.getValue returns something like: "yourtextIntellijIdeaRulezzzzzz" in that place:
, but at the same time this code inside ReferenceContributor during tha call of literal.getValue returns normal value without "IntellijIdeaRulezzzzzz":
Oh, I understood. Instead of using
it should be used
Thanks again!
Actually, using originalPosition won't probably always function as you imagine it to. This rulezzz thing is a dummy identifier inserted to make writing completion easier for you. See again the javadoc on CompletionContributor, search by keyword "dummy identifier".
I see. Thanks)