CLion 2023.1 Help

Develop plugins for CLion

When you miss certain functionality in CLion, you may consider writing your own plugin. This article is intended to help you grasp the basics of the IntelliJ Platform plugin development and guide you through the very first steps of implementing your CLion plugin.

Any CLion plugin is an extension to the IntelliJ Platform, so in general it is a specific Java project. There are two supported workflows for IntelliJ plugin development: either using gradle-intellij-plugin with Gradle as a build system (the recommended way) or DevKit with the IntelliJ IDEA’s own build system.

As an IDE for your plugin development, use IntelliJ IDEA Community or Ultimate edition.

Apart from the IntelliJ IDEA itself, you will need a target CLion distribution. With the Gradle-based approach, it can be downloaded automatically by the build script. In case of using DevKit, make sure to install CLion manually.

Platform Open API

CLion doesn’t provide its own public API with the guaranteed stability and detailed descriptions, yet you can use all the features of the Platform Open API. An effective way to explore the Platform API is to obtain and inspect the sources of the IntelliJ IDEA Community Edition from the official repository.

The API of the IntelliJ Platform can change between releases and therefore affect plugins functionality. Such changes are listed in Incompatible Changes in IntelliJ Platform and Plugins. Note that CLion internal SDK might change at any point without prior notice.

For assistance with the API usage for your CLion plugin, feel free to ask on the community forum.

Extensions

IntelliJ Platform provides extensions and extension points for the plugins to add new or customize the existing functionality. A plugin should declare that it implements one or several extensions <extenstions> or extension points <extensionPoints> in the plugin.xml file. To get the list of the available extensions and extension points, explore the *Extention/*ExtentionPoints files in this directory of the Community Edition sources.

Some of the common extension points are the following:

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 <depends> tag in plugin.xml (see Plugin Compatibility with IntelliJ Products).

Some modules are available in all IntelliJ-based products, while the following modules are available specifically in CLion:

  • com.intellij.modules.cidr.lang - C/C++ language support (this module is also available in AppCode and Android Studio);

  • com.intellij.modules.cidr.debugger - native debuggers support (also in AppCode and Android Studio);

  • com.intellij.modules.clion - core CLion functionality.

Plugin.xml file

The plugin.xml file is a key plugin descriptor that contains the plugin metadata: name, description, author, changelog, and the list of the implemented features.

The values of name, id, description, and vendor are required to get your plugin registered correctly in the plugin database. Every depends parameter, as mentioned above, is an ID of a module the plugin depends on; the list of the depends parameters implicitly defines the compatible products.

Getting started with a CLion plugin

Further on, we’ll focus on the Gradle-based approach as the recommended one for all new plugin projects. The DevKit workflow, which is still supported for existing plugins, is described in Using DevKIt.

First of all, install IntelliJ IDEA Community or Ultimate. And before you start, check that two bundled plugins, Gradle and DevKit, are both enabled in your IntelliJ IDEA instance (go to Settings | Plugins | Installed and search for the plugins by name).

Gradle-based workflow

Let’s take a basic example of a plugin that adds Greetings to the IDE main menu and customize it for CLion.

  1. Create a new Gradle project with the IntelliJ Platform Plugin selected in the list of Additional Libraries and Frameworks:

    new gradle project for clion plugin
  2. Follow through the process of creating a new Gradle project. It’s recommended to select the Use default gradle wrapper option - that way, IntelliJ IDEA will automatically configure everything you need to run Gradle tasks:

    gradle wrapper for clion plugin
  3. When the template plugin project is ready, invoke the Gradle tool window from View | Tool Windows | Gradle and notice the runIde task. This task launches the plugin’s target IDE (by default, it’s configured to be IntelliJ IDEA):

    template plugin project

    See the full list of the tasks provided by the gradle-intellij-plugin.

  4. Now let’s modify the default project:

    • Add a new Java class called HelloAction:

      import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; public class HelloAction extends AnAction { public HelloAction() { super("Hello"); } public void actionPerformed(AnActionEvent event) { Project project = event.getProject(); Messages.showMessageDialog(project, "Hello world!", "Greeting", Messages.getInformationIcon()); } }
    • Place the following dummy code into plugin.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> <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>
    • Change the intellij entry in the build.gradle script (for details, refer to Setup DSL):

      intellij { version 'LATEST-EAP-SNAPSHOT' type 'CL' }

      CLion was published to the Maven-compatible artifacts repository along with the 2019.2 EAP. So currently, you can use either LATEST-EAP-SNAPSHOT or 191-EAP-SNAPSHOT as a version specifier.

  5. Now we can run the runIde task and see Greetings in the CLion main menu:

    new menu item as a plugin

Further steps

The above example is very basic, it employs only the common IntelliJ functionality without CLion specifics. To dig deeper, explore the Plugin Structure section and CLion Plugin Development in the SDK documentation, IntelliJ SDK docs FAQs and the community forum.

If you are interested in developing a plugin for custom language support, refer to the dedicated section in the Platform SDK documentation, and take a look at Antlr's plugin development notes. The PSI Viewer plugin can help you get familiar with the Program Structure Interface, PSI.

See also the guidance docs on testing your plugin. The topic of publishing a plugin is discussed in Publishing plugins with Gradle and Publishing DSL.

Last modified: 11 January 2023