Search code examples
intellij-plugin

How do you support com.intellij.psi for a plugin targeting pycharm?


In my plugin, I'm using com.intellij.psi.PsiMethod and com.intellij.psi.PsiClass. When I target Pycharm with my alternativeIdePath and try to use my plugin, I get a NoClassDefFound error for both classes mentioned above. There are 2 parts to my question:

  1. Should I be using python specific psi classes (PyFunction/PyClass) or are the base com.intellij.psi classes compatible with pycharm already?

  2. If I do need to include a different psi module/library, what would that look like in my build.gradle file?

My intellij section in build.gradle looks like this:

intellij {
  version '182.4505.22'
  alternativeIdePath "redacted\\Toolbox\\apps\\PyCharm-P\\ch-0\\182.4505.26"
}

My project sdk is JDK1.8, and in my module dependencies I have Gradle: com.jetbrains:ideaIC:182.4505.22, tools.jar, pycharm.jar, and Module Sources.


Solution

  • The com.intellij.psi.PsiClass and PsiMethod are not "base PSI classes", they are Java PSI classes, and they aren't available in products that do not support Java. In PyCharm, you need to use PyFunction/PyClass.

    To build a plugin that supports both IntelliJ and PyCharm, you need to add the Python plugin as a dependency for your plugin in build.gradle (it provides the same API as PyCharm). In your plugin.xml you need to use optional dependencies on com.intellij.modules.java and com.intellij.modules.python, so that your Java-dependent components are only loaded in a Java IDE, and your Python-dependent components are only loaded in PyCharm.