Developing an Intellij IDEA Plugin for a Custom Language— Tutorial 1-Setting up the environment
As my first intern project at WSO2, Inc I got the chance to develop a plugin for the Siddhi language. Siddhi is a query language which is used inside the WSO2 Complex Event Processor. Building this plugin was a challenging task because the documentation given by @intellijidea on developing a custom plugin is not descriptive enough, specially when implementing the debug functionality in the plugin. So I thought to share my knowledge on developing a custom language plugin for Intellij IDEA.
Custom Language Support
Custom language support provides basic functionality for working with a particular programming language. This includes:
- File type recognition
- Lexical analysis
- Syntax highlighting
- Code insight and code completion
- Debugger support
- Intention actions
- Spell Checker
- Structure View
In this tutorial series I will be working on the above tasks.
So as the first step we need to setup the plugin development environment.
1) Install Intellij IDEA
You need to install IntelliJ IDEA version 9.0 or later (either Community Edition or Ultimate) on your computer.
2) Clone and build IntelliJ IDEA Community Edition source code (optional)
Even though this is a optional step this will make it much easier for you to debug your plugins. So I recommend to do this.
The source code of IntelliJ IDEA Community Edition is stored in a Git repository. Therefore, in order to check out the sources, you need to have Git installed. Check this link to get to know on how to install git.
Checkout the code
You have 2 methods to checkout the code.
- Via IntelliJ IDEA:
- Select VCS ->Checkout from Version Control ->Git from the main menu
- In the Git Repository URL field, enter
2. Checking out from the command line:
Please execute the following command:
git clone --depth 1 git://git.jetbrains.org/idea/community.git idea
Building and running the code
getPlugins.batfrom the project root directory to check out additional modules.
- Open the project.
- If an error notification about a missing required plugin (e.g. Kotlin) is shown enable or install that plugin.
- Configure a JSDK named “IDEA jdk” (case sensitive), pointing to an installation of JDK 1.8.
- Unless you’re running on a Mac with an Apple JDK, add
/lib/tools.jarto the set of “IDEA jdk” jars.
- Configure a JSDK named “1.8”, pointing to an installation of JDK 1.8.
/lib/tools.jarto the set of “1.8” jars.
- Use Build -> Make Project to build the code.
- To run the code, use the provided shared run configuration “IDEA”.
3) Configuring IntelliJ Platform SDK
- Create a new IntelliJ Platform SDK under File ->Project Structure:
- Specify the installation folder of IntelliJ IDEA Community Edition as the home directory.
- Select the IDEA jdk created earlier in step 2 as the default Java SDK:
- In the Sourcepath tab of the SDK settings, click the Add button:
- Specify the directory into which you have checked out the sources of the Community Edition:
4) Adding useful plugins
In order to develop plugins in intellij idea Plugin DevKit plugin must be enabled in IDE.
Go to File->Settings->Plugins and search for Plugin Dev kit and enable it if it is not enabled yet.
If your custom language is written using ANTLR4 install the ANTLR v4 grammar plugin. It will be helpful in future work.
You have successfully created the intellij idea plugin development environment. :)
Next tutorial will be on Creating a plugin project.
Stay tuned. ;)