Is it possible to extend template language support - Velocity with SQL?
So the idea is plugin to help working with Apache Cayenne. I have .xml files with SQL statements (written using velocity syntax) and I'd like to add code higilighting + autocomplete (and maybe other features like syntax highliter) for specific files (listed in cayenne.xml file).
So the question is - can I somehow use existing functionality and extend it? Or should I make a custom language support plugin from scratch?
And is there any way to apply all custom language features only to specific files? Like, I know that I want .xml files. But only the ones which are specified in other .xml file. I can use DOM model to read this file and find all filenames, this part is easy. But can I use this list of filenames somehow?
请先登录再写评论。
Could you please provide some examples of how the definitions you mention look like, what's an XML with SQL written using Velocity syntax? How are files referenced in that another XML?
cayenne.xml looks something like
I see. This is the case for language injection, and you may even avoid the requirement to have a list of XML files for that. The problem is, though, that template languages can't be injected currently together with their template data. So you can inject either Velocity (not possible currently, but can be supported) or SQL, but not both at the same time. Completion for which of those languages do you need more?
You could try to work around that with a custom language plugin, by providing your own MultiHostInjector which takes the CDATA value, carefully removes all the Velocity markup ranges from it and then injects SQL into the remaining parts. You could even try injecting Velocity into the markup ranges. That might work, but requires quite some effort.
Thank you very much for the answers, I'll try the MultiHost Injector, seems like pretty interesting thingy :) And injecting SQL or Velocity works just fine for whole <sql> tag, so no point in making some kind of plugin.
Maybe you know some examples of code using the MultiHostInjector? Source code is pretty self-explanatory, but won't hurt to have some more examples :)
AFAIK there are no tutorial-like examples, but there are some real usages in intellij-community source, particularly in "IntelliLang" directory, e.g. DefaultLanguageInjector.
Thanks again for the answers!