How to get the parent psi element outside of a language injection

Answered

Hello fellows,

I'm in the middle of a plugin development and now I have some struggles with the language injection.

I want to add auto completions for a specific code position, but I need some information of the previous elements, which are an another language. I can't add them to my language.

Example:

name="someContent"

"someContent" is my language.
"name" is the information, which I need. This is the other language.

 

I hope you could help me. :)

 

Kind regards,

Fabian

2 comments
Comment actions Permalink
Official comment

Invoking psi.getContext in a loop (orPsiTreeUtil.getContextOfType) will eventually switch from injected to host PSI.

Comment actions Permalink

Hi Peter,

thank you very much! The following code worked for me. :)

PsiTreeUtil.getContextOfType(
completionParameters.getPosition(), XmlAttributeValue.class
);


Kind regards,
Fabian

1

Please sign in to leave a comment.