Implement multiple languages in plugin Follow
Is it possible to implement HTML language and Java for a custom language plugin?
So the plugin should handle 3 languages:
1. rythm (custom language)
Please sign in to leave a comment.
Actually, you may support a custom language in your plugin, and configure dependency of your plugin on other language plugins, as needed.
For example, the Groovy plugin depends on the Java plugin, so it's able to interoperate with it and reuse the code from it.
How can I configure the dependency?
My plugin can handle now HTML and rythm. It would be great if I could add java language to the plugin.
You need to add the line <depends>com.intellij.modules.java</depends> to your plugin's META-INF/plugin.xml, and add a dependency to java-impl in your module's properties.
Here's how it's done in JavaFX: https://github.com/JetBrains/intellij-community/blob/306d705e1829bd3c74afc2489bfb7ed59d686b84/plugins/javaFX/src/META-INF/common-javaFX-plugin.xml - there are dependencies on Java and on Properties plugins.
I'll try that. :)
After adding java-impl to the module's properties this error appears
Did I forgot something?
Ok after I added java-impl to Global Libraries it looks alright.
But I still can't use Java features in my plugin.
Sorry for misleading comment, the java-impl is already bundled within IntelliJ IDEA, so you don't need to add it as a dependency.
Please remove it, and try to use a Java-specific class in your code, like JavaElementVisitor to see if it's available.
I added these extensions to the plugin.xml but it's still not working.
I also tried to change to:
For example I want to get a code completion for packages.
Unfortunately it's not that easy, and it depends on what you're going to achieve.
If you want to mix Java and your language in the same file, it's definitely possible, but very difficult.
If your language is only going to use classes and methods written in Java, it's much easier, but not for free anyway. You still need to provide your own implementation of completion, syntax highlighting, and everything, but you can reuse the Java language API, e.g. to get the Java packages and classes defined in your project.
For example, the Groovy and JavaFX plugins do that, maybe you can do something similar.
Okay, thanks Pavel.
Option 2 is what I need.
The plugin already can Highlight HTML and my custom language. Code completion for my custom language is also working.
Now the only thing I want to implement is the Java language.
Is there anything I need to change or add in my project structure?
For me it looks like Groovy is using language injection to implement java language.
Could you please be more specific on what you need from the Java language?
For example, how the things in your language are connected with Java? Or which things from Java you're going to reuse?
I need the Java package and classes completion contributor and also Java keyword highlighting.
The plugin should support rythm (which is a template engine).
The syntax from rythm starts with @. It's pretty much the same as java.
The completion of packages and classes is done via JavaClassReference. You don't need to create it yourself, just use JavaClassReferenceProvider like it's done in org.jetbrains.plugins.javaFX.fxml.refs.ImportReferenceProvider. In the line "@import a.b.C" each of the identifiers a, b, and C should have a JavaClassReference to the corresponding package or class.
Regarding the highlighting, do you want the Java fields and methods to be colored? If so, you need to use reference to PsiMethod (or PsiField) on each your identifier referencing Java method (or field). You'll be able to check if the method or field exists (and highlight with red if it doesn't), and you'll get the navigation to Java code.
Thanks a lot, Pavel!!