Embedded langue in PSIComment
Hi,
I'm trying to create a plugin where you would be able to write a language inside of PSIComments either by extending the PSIComment or by replacing the comment with another PSIElement. The main point is that the compilation of the chosen code language should not care about the embedded language. The embedded language is only used for creating visualisations and some other parsing things. The language that I want to embed is defined in a .bnf and a .flex file and works when trying it in a filetype for that language.
I have tried:
- using Injected Language but that only seems to work on string literals and will therefore not work in a PSIComment.
At the moment we are trying to replace a PSIComment by the PSIElement of the defined language but it is generating errors. Is there a way to do it this way by somehow extending the PSIComment with our language?
Thanks for any ideas or help!
Please sign in to leave a comment.
What are your target languages where injection should work? The default implementation (com.intellij.psi.impl.source.tree.PsiCommentImpl) does support language injection, thus it might work in your use case.
The hope was that it would work in any language, that would make the plugin most useful. We could settle for just Java for now to prove the concept.
Did you say that language injection is possible for PSIComment or is it a typo?
Yes, it works for com.intellij.psi.impl.source.tree.PsiCommentImpl which is used by many languages indeed. For Java, it's used for line comments only though, so language injection in javadoc elements is currently not available (see https://youtrack.jetbrains.com/issue/IDEA-113589).
Okay, thanks! We are mostly interested in line-comments anyways so that's fine. Do you know of any examples where language injection has been used in comments? Or is there any other examples of how to do it?
Thanks!
Not specific to injecting in comments, but you can take a look at existing OSS plugins using language injection https://plugins.jetbrains.com/intellij-platform-explorer/?extensions=com.intellij.multiHostInjector
Thanks for the help will take a look!