Language plugin - adding support for multiple languages in one file
Planned
I'm creating a RubyMine plugin for RBlade, a blade-like templating language for Ruby on Rails. I'm basically trying to recreate the Blade plugin for PHPStorm, but I'm having trouble getting three languages to mix in an RBlade file: I can get RBlade directives and HTML to mix fine, but cannot figure out how to get Ruby to work in the same file.
I've tried:
-
Adding Ruby as a third language in the MultiplePsiFilesPerDocumentFileViewProvider (see commented out code)
- Ruby here seems to be looking at the HTML PSI structure instead of the RBlade PSI structure when trying to inject?
- Adding a MultiHostInjector
- Adding a LanguageInjectionContributor
The latter two I think I'm just implementing wrong, but I can't get them to actually do anything, even when removing any checks for the type of element to work on.
I'm not sure how the Blade plugin gets PHP to work inside Blade templates - is there somewhere I can see how it does it? What's the best approach to get third language support in a file?
Please sign in to leave a comment.
Update: I've managed to get the language injection working by adding my Ruby expression token to the `ParserDefinition::getCommentTokens()` token set.
While this has worked, it seems like a hack and not a proper solution? Any ideas?