我正在为 Intellij Idea 制作插件,在项目创建阶段遇到问题。
当我在项目创建向导“其他库和框架:”中单击我的插件时,会出现一个中间带有“无可显示”的大方块。 我必须单击“下一步”按钮才能显示我的设置。 我不明白是什么原因造成的。如果你需要的话,在我的plugin.xml下面。
<!-- Copyright 2000-2023 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -->
<!-- Plugin Configuration File. Read more: https://plugins.jetbrains.com/docs/intellij/plugin-configuration-file.html -->
<idea-plugin>
<!-- Unique id for this plugin. Must stay constant for the life of the plugin. -->
<id>org.intellij.sdk.project.wizard</id>
<!-- Text to display as name on Settings | Plugin page -->
<name>SDK: Project Wizard Demo</name>
<!-- Product and plugin compatibility requirements -->
<depends>com.intellij.modules.platform</depends>
<!-- Text to display as description on Settings | Plugin page -->
<description>
<![CDATA[
Demonstrates working with the Project Wizard.
]]>
</description>
<change-notes>
<![CDATA[
<ul>
<li><b>2.0.0</b> Convert to Gradle-based plugin</li>
<li><b>1.0.0</b> Release 2018.3 and earlier.</li>
</ul>
]]>
</change-notes>
<!-- Text to display as company information on Settings | Plugin page -->
<vendor url="https://plugins.jetbrains.com">IntelliJ Platform SDK</vendor>
<extensions defaultExtensionNs="com.intellij">
<moduleType
id="DEMO_MODULE_TYPE"
implementationClass="org.intellij.sdk.project.wizard.DemoModuleType"/>
</extensions>
</idea-plugin>
更新:
我设法将“其他库和框架:”部分替换为我的插件的向导步骤。然而现在,当我按“下一步”时,会出现重复的内容。
更新2: 以下是我的代码的 Pastebin 链接:
DemoModuleWizardStep.java: https://pastebin.com/tHSw0bbS
DemoModuleType.java: https://pastebin.com/QBh5LkDg
DemoModuleBuilder.java: https://pastebin.com/BBhCMPNd
另外,我正在编辑此处找到的 IntelliJ IDEA 代码: https://github.com/JetBrains/intellij-sdk-code-samples/tree/main/project_wizard
根据您提供的信息和 Pastebin 链接,让我们尝试诊断问题。
“没有什么可显示”问题: 当您的自定义
ModuleWizardStep
未在 ModuleBuilder
中正确初始化或正确返回时,通常会出现“无内容可显示”问题。
复制向导步骤: 当您在单击“下一步”后说“出现重复项”时,通常意味着您的
ModuleBuilder
正在返回自定义 ModuleWizardStep
的多个实例。
让我们解决问题:
确保您的
DemoModuleBuilder
的 getModuleType()
方法返回正确的 ModuleType
。您从 getModuleType()
返回的实例应与在您的 plugin.xml
中注册的实例匹配。
在
DemoModuleBuilder.java
:
@Override
public ModuleType<?> getModuleType() {
return DemoModuleType.getInstance();
}
并在
DemoModuleType.java
中,确保您的 DemoModuleType
单例已正确初始化:
public static DemoModuleType getInstance() {
return (DemoModuleType) ModuleTypeManager.getInstance().findByID(ID);
}
确保您仅在
ModuleWizardStep
的 getCustomOptionsStep()
中返回 DemoModuleBuilder
的一个实例。还应该检查任何其他可以返回 ModuleWizardStep
的方法,以确保它们不会无意中添加额外的步骤。
在
DemoModuleBuilder.java
:
@Override
public ModuleWizardStep[] getCustomOptionsStep(WizardContext context, Disposable parentDisposable) {
return new ModuleWizardStep[]{
new DemoModuleWizardStep()
};
}
确保如果您覆盖
createWizardSteps()
等其他方法,它们不会无意中添加额外的步骤。
有时,组件和依赖项的初始化顺序可能会产生此类问题。确保您的
ModuleBuilder
、ModuleType
和 ModuleWizardStep
在使用前已正确初始化,并且正确设置了它们的依赖项(如果有)。
确保您使用最新版本的 IntelliJ SDK 并参考最新的文档和代码示例。有时,问题可能是由于旧版本中的错误造成的,或者 SDK 中可能存在您需要注意的更改或更新。
使用 IntelliJ IDEA 中的断点和调试器逐步完成项目创建过程。这将帮助您准确识别添加步骤的位置和时间,并深入了解任何异常情况。
如果经过上述步骤后,问题仍然存在,您可能需要深入了解 SDK 内部,或者向 JetBrains 官方论坛或插件开发渠道寻求帮助,因为问题可能更加复杂,可能需要更深入的了解SDK 的内部结构。