Finding declarations in an injected language.

Answered

I am writing a plugin for a custom language that is injected into python string literals. Imagine something like this:

code = [ 
  "$foo = 3", // My language is injected in these string literals
  "$bar = $foo", // command clicking $foo should jump to the definition in the previous line.
]

The custom language plugin tutorial shows finding all declarations by finding all the files with your language extension in the project and then searching them: link. This doesn't work in this case as the injected `PsiFile`s are not found. I did find this post from 10 years ago asking the same question but it didn't really recieve an answer.

Hopefully sometthing has changed in the last decade/there is a different way of achieving my desired behavior.

Thanks!

0
1 comment

Okay I've figured out the solution.

Once you find the files you want to search you can iterate over them to find all of the `PsiLanguageInjectionHost`s.

Then you can use `InjectedLanguageManager.getInjectedPsiFiles` on those hosts to get the psi files.

 

0

Please sign in to leave a comment.