How to use classes of pythonPlugin? always compile failed, say can't find package

Answered

I create a gradle plugin project, by the document way(https://plugins.jetbrains.com/docs/intellij/gradle-guide.html)。Then I add the python's depend:

<depends>com.intellij.modules.python</depends>

But it report an error:

Cannot resolve plugin 'com.intellij.modules.python' in dependencies (Reference: Plugin Dependencies)


I find a way to resolve it: https://intellij-support.jetbrains.com/hc/en-us/community/posts/4416336449554-The-lack-of-python-jar-python-ce-jar-in-IntelliJ-Platform-Plugin-SDK-cause-a-error-of-resovle-plugin-depends-com-intellij-modules-python-
But when I build the project (use intellj.buildPlugin), it reported an error: 

错误: 程序包com.jetbrains.python.psi不存在 (Error: Package com.jetbrains.python.psi does not exist)

import com.jetbrains.python.psi.PyFunction;
^

How can I fix the error ? I want to use the Python PSI in my Plugin.
Thanks for your answer !

0
3 comments

You must set/add Python dependencies as described here first: https://plugins.jetbrains.com/docs/intellij/pycharm.html

1

Hi Yann Cebron,

Thanks for your help. I have followed the steps to set it up, but still fail. This is my "build.gradle" and "plugin.xml":

Is there anything wrong?

build.gradle

plugins {
id 'org.jetbrains.intellij' version '1.4.0'
id 'java'
}

group 'com.sannmizu.example'
version '1.0-SNAPSHOT'

sourceCompatibility = 11

repositories {
mavenCentral()
}

dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}

// See https://github.com/JetBrains/gradle-intellij-plugin/
intellij {
version = '2021.3.2'
type = 'PC'
downloadSources = false
sandboxDir = 'D:\\Project\\Sandbox'
}

patchPluginXml {
changeNotes = """
Add change notes here.<br>
<em>most HTML tags may be used</em>"""
}

test {
useJUnitPlatform()
}


plugin.xml

<idea-plugin>
<id>com.sannmizu.example.StepPlugin</id>
<name>Step Tc Tp</name>
<vendor email="sannmizu@qq.com">Sannmizu</vendor>

<description>
.tc .tp文件的简单转到插件,能够点击函数直接跳转,提供了函数名补全,路径补全
</description>

<!-- please see https://plugins.jetbrains.com/docs/intellij/plugin-compatibility.html
on how to target different products -->
<depends>com.intellij.modules.platform</depends>
<depends>com.intellij.modules.xml</depends>
<depends>com.intellij.modules.lang</depends>
<depends>com.intellij.modules.python</depends>


<extensions defaultExtensionNs="com.intellij">
<!-- Add your extensions here -->
<fileType name="TestPoint" implementationClass="com.sannmizu.example.step.TestPointFileType" fieldName="INSTANCE" language="TestPoint" extensions="tp"/>
<fileType name="TestCase" implementationClass="com.sannmizu.example.step.TestCaseFileType" fieldName="INSTANCE" language="TestCase" extensions="tc"/>
<psi.referenceContributor implementation="com.sannmizu.example.step.TestCaseReferenceContributor"/>
</extensions>

<actions>
<!-- Add your actions here -->
</actions>
</idea-plugin>
0

I find that add the dependency to the "PythonCore" can resovle it:

https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html#3-dependency-declaration-in-pluginxml 

Dose this complict with the description "No specific declaration is needed to use PY or PC APIs." ?

0

Please sign in to leave a comment.