Develop plugins for CLion
Language: Java or Java-based (refer to Kotlin for Plugin Developers)
IDE: IntelliJ IDEA Community / Ultimate
Workflow: Gradle-based - recommended for new plugins, DevKit - supported for existing plugins
Available API: IntelliJ Platform API
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.
tip
For more information, refer to Plugin development Quick Start Guide in the Platform SDK documentation.
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.
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.
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:
Actions - menu and toolbar items.
Code inspections - static code analysis.
Intentions - context-specific actions available in the editor.
Your plugin may depend on classes from other plugins. In this case, plugins can be either bundled, third-party or even your own. For more information about expressing 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 (refer to 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 Android Studio);com.intellij.modules.cidr.debugger
- native debuggers support (also in Android Studio);com.intellij.modules.clion
- core CLion functionality.
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.
tip
You can find examples of the plugin.xml files in the IntelliJ SDK Docs Code Samples repository.
tip
Take a look at the sources of some ‘CLion-only’ plugins: Compiler Explorer, Conan plugin, CMake QuickDocs.
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).
Let’s take an example of a plugin that adds Greetings to the IDE main menu and customize it for CLion.
Create a new Gradle project with the IntelliJ Platform Plugin selected in the list of Additional Libraries and Frameworks:
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:
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):
See the full list of the tasks provided by the gradle-intellij-plugin.
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 more information, 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
or191-EAP-SNAPSHOT
as a version specifier.
Now we can run the runIde task and see Greetings in the CLion main menu:
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.
Thanks for your feedback!