Access editor within PsiReferenceContributor - Originally injected PsiElement

Hi guys

I am trying to convert code which was originally only using a Contributor implementation, to provide full PsiReference contribution.
The contribution itself is available for an Injected language, contained within an XmlFile

I am looking for any of the following information when implementing PsiReferenceContributor/PsiReferenceBase
    - The originally injected Xml PsiElement
    - The Editor, to get the caret position
    - The caret position

The old code within the CompletionContributor provided a method addCompletions, which allowed access to CompletionParameters which contained the Editor

I initially tried the following code snippet from within my PsiBase getVariants implementatoin

    psiFile = InjectedLanguageUtil.getTopLevelFile(element)
    editor = PsiUtilBase.findEditor(psiFile)

This allows my tests to pass, but throws an exception when deploying to IJ.

         Access is allowed from event dispatch thread only.
         Details: Current thread: Thread[ApplicationImpl pooled thread 12,4,main] 8012416
         Our dispatch thread:Thread[AWT-EventQueue-0 13.0.2#IU-133.696, eap:false,6,main] 21189219
         SystemEventQueueThread: Thread[AWT-EventQueue-0 13.0.2#IU-133.696, eap:false,6,main] 21189219

InjectedLangaugeUtil doesn't provide any mechanism to get this information either

Any comments are appreciated :)

1 comment
Comment actions Permalink

I have been able to gain access to the original PsiElement that was injected through the use of the InjectedLanguageManager- rather than using the Util class.

Example Code -




Please sign in to leave a comment.