How to access PSI structure for both Java, Python in a single Intellij Plugin

22 Views Asked by At

I am developing a plugin for Pycharm, Intellij IDEA. Need to access PSI features (PSIMethod(java class) & PyFunction) for Java and Python language in both the IDEs versions (2022.3.1 and above) Unable to write a common plugin which can work on both PyCharm & IDEA.

Later we want to extend our plugin to support other languages like c/c++ also.

How can we achieve this functionality?

In plugin.xml added optional dependencies which lets us install our plugin in both IDEA & PyCharm irrespective of the availibility of the java or python plugin.

<depends config-file="jetbrains-java.xml" optional="true">com.intellij.java</depends>
<depends config-file="jetbrains-python.xml" optional="true">com.intellij.modules.python</depends>

In build.gradle.kts, I have

intellij {
    version.set("2022.3.1")
    type.set("IC")
    plugins.set("com.intellij.java, PythonCore:223.8214.16")
}

However, hardcoding the PythonCore version, limits our plugin functionality to only the supported products listed in https://plugins.jetbrains.com/plugin/7322-python-community-edition/versions/stable/263951 But we also want to support later versions of these products like Android Studio Hedgehog.

1

There are 1 best solutions below

0
ice1000 On

I think what you're doing is the intended way of adding support for other languages. The setPlugins sets the plugins installed for the runIde task, it does not specify the version of the plugin that needs to be there.

So, if you setPlugins with a 2022.3 version of the Python plugin, it will work with the 2023 version of the Python plugin, it's just that it will be compiled with the old version.

See: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html