有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java使用IntelliJ 2019.3.1为Clion开发插件。如何为我的插件项目添加C++语言支持?

我目前正在学习为IntelliJ IDE编写插件。我特别感兴趣的是 为CLion开发插件。因此,我想为C++插件添加对C++的支持。p>

我的问题是:

我在文档中读到了如何开发C++插件。然而,这种描述方式对我来说并不适用。IntelliJ无法解析我要添加的依赖项

我现在知道:

1 This部分文档解释了插件可能依赖于其他插件, 以及如何添加依赖项

Plugin dependencies

Your plugin may depend on classes from other plugins. In this case, plugins can be either bundled, third-party or even your own. For instructions on how to express the dependencies, refer to Plugin Dependencies.

Your plugin should specify which product or products it will be compatible with (all IntelliJ-based IDEs, CLion only, or some subset). You can do that by declaring module dependencies with the tag in plugin.xml (see Plugin Compatibility with IntelliJ Products).

2This文档的一部分解释了哪个插件包含哪些功能。每种特定的语言似乎都是一个插件。所以开发一个想要解析C++的插件,将依赖于C++插件。p>

Modules Specific to Functionality More specialized functionality is also delivered via modules and plugins in IntelliJ Platform-based products. For example, the com.intellij.modules.python module supports the Python language-specific functionality. If a plugin uses functionality from this module, such as Python-specific inspections and refactoring, it must declare a dependency on this module.

...

The following table lists(1) modules or built-in plugins that provide specific functionality, and the products that currently ship with them.

根据上面提到的表,我需要添加^ {CD1>}作为C++的依赖项。然而,当我把这一行添加到我的plugins.xml文件中时,cidr将被删除。语言部分不被识别

3在关于java插件开发的thisStackoverflow问题中,有人回答说最近有一个变化,现在还必须添加所需的插件来构建。格雷德尔。此外,java语言支持现在变成了一个内置插件

我猜该怎么办

我猜C++的支持现在也是一个插件了吗?但我该怎么加呢

所以

intellij {
    version '2019.2'
    plugins 'java'
}

也许我需要这样的东西

intellij {
    version '2019.2'
    plugins 'c++' // or maybe cidr??
}

附录

我的java类:

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.ui.Messages;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiRecursiveElementWalkingVisitor;
//import com.jetbrains.cidr.lang.psi.OCFunctionDefinition; <-- This import does not work 
public class HelloAction extends AnAction {
    public HelloAction() {
        super("Hello");
    }

    @Override
    public void actionPerformed(AnActionEvent anActionEvent) {
        Editor editor = anActionEvent.getData(CommonDataKeys.EDITOR);
        PsiFile psiFile = anActionEvent.getData(CommonDataKeys.PSI_FILE);
        if (editor == null || psiFile == null) return;
        int offset = editor.getCaretModel().getOffset();

        final StringBuilder infoBuilder = new StringBuilder();
        PsiElement element = psiFile.findElementAt(offset);
        infoBuilder.append("Element at caret: ").append(element).append("\n");
        Messages.showMessageDialog(anActionEvent.getProject(), infoBuilder.toString(), "PSI Info", null);

        psiFile.accept(new PsiRecursiveElementWalkingVisitor(){
            @Override
            public void visitElement(PsiElement element) {
                super.visitElement(element);
                infoBuilder.append(element.getText()).append("\n");

            }
        });
    }

    @Override
    public void update(AnActionEvent e) {
        Editor editor = e.getData(CommonDataKeys.EDITOR);
        PsiFile psiFile = e.getData(CommonDataKeys.PSI_FILE);
        e.getPresentation().setEnabled(editor != null && psiFile != null);
    }
}

我的身材。渐变文件

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

group 'org.example'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

// See https://github.com/JetBrains/gradle-intellij-plugin/
intellij {
    version 'LATEST-EAP-SNAPSHOT'
    type 'CL'
}
patchPluginXml {
    changeNotes """
      Add change notes here.<br>
      <em>most HTML tags may be used</em>"""
}

我的插件。xml

<idea-plugin>
    <id>org.helloplugin</id>
    <name>Hello Action Project</name>
    <version>0.0.1</version>
    <vendor email="dummy" url="dummy">dummy</vendor>

    <depends>com.intellij.modules.lang</depends>
    <depends>com.intellij.modules.cidr.lang</depends> // cannot be resolved

    <extensions defaultExtensionNs="com.intellij">
    </extensions>

    <actions>
        <group id="MyPlugin.SampleMenu" text="Greeting" description="Greeting menu">
            <add-to-group group-id="MainMenu" anchor="last"/>
            <action id="Myplugin.Textboxes" class="HelloAction" text="Hello" description="Says hello"/>
        </group>
    </actions>
</idea-plugin>

共 (1) 个答案

  1. # 1 楼答案

    我在文件中找到了答案。我只是需要重新导入这个项目

    Exploring Module and Plugin APIs

    Once the dependency on a module or plugin is declared in plugin.xml, it’s useful to explore the packages and classes available in that dependency. The section below gives some recommended procedures for discovering what’s available in a module or plugin on which a project depends. These procedures assume a project has the build.gradle and plugin.xml dependencies configured correctly. Exploring APIs as a Consumer

    Exploring the available packages and classes in a plugin or module utilizes features in the IntelliJ IDEA IDE.

    If the project is not up to date, Reimport the Gradle project as a first step. Reimporting the project will automatically update the dependencies.

    对于C++语言的支持,不需要添加一些东西来构建。格拉德尔

    我的插件。xml

    <idea-plugin>
        <id>org.helloplugin</id>
        <name>Hello Action Project</name>
        <version>0.0.1</version>
        <vendor email="dummy" url="dummy">dummy</vendor>
    
        <depends>com.intellij.modules.platform</depends>
        <depends>com.intellij.modules.lang</depends>
        <depends>com.intellij.modules.cidr.lang</depends>
    
    
        <extensions defaultExtensionNs="com.intellij">
        </extensions>
    
        <actions>
            <group id="MyPlugin.SampleMenu" text="Greeting" description="Greeting menu">
                <add-to-group group-id="MainMenu" anchor="last"/>
                <action id="Myplugin.Textboxes" class="HelloAction" text="Hello" description="Says hello"/>
            </group>
        </actions> </idea-plugin>