Custom language plugin development for Intellij IDEA — Part 01

Shan Mahanama
4 min readAug 20, 2017

--

For the last few months, I had the rare opportunity to work in the Ballerina language development team and the Ballerina IDEA plugin team at WSO2. In this period of time, I have learnt a lot about language development and Intellij IDEA plugin development. So from this series of articles, I want to share what I have learnt about Intellij IDEA custom language plugin development. If you have ever developed a plugin for Intellij IDEA, you know that there are limited amount of resources to learn. So hopefully, these articles will fill the gaps and will be helpful to beginners.

Main types of plugins in Intellij IDEA

The most common types are,

  • Custom language support
  • Framework integration
  • Tool integration
  • User interface add-ons

Custom Language Support in Intellij IDEA

Custom language support provides basic functionality for working with a particular programming language. This includes,

  • File type recognition
  • Lexical analysis
  • Syntax highlighting
  • Formatting
  • Code insight and code completion
  • Inspections and quick-fixes
  • Intention actions

Creating the Simple language plugin

So as our custom language, we choose Simple language. Extension of files of this language will be .s. An example would be test.s file. From this article, we only focus on setting up the project properly and implementing the file type recognition. Once we do this correctly, we can start development very easily. In this tutorial, I will deviate lot from the custom language plugin development tutorial provided by JetBrains because I want you to learn something new.

Creating a new Gradle project

First we need to create a Gradle project.

Creating a new Gradle projet
Creating a new Gradle project
Creating a new Gradle project
Creating a new Gradle project
Directory structure

So after creating a new Gradle project, you should have a directory struture like above.

Adding file type recognition support

In this section, we associate .s extension to our plugin.

Step 1 — Updating the build.gradle file

We need to update the Gradle build script so that we can use the tasks of the intellij gradle plugin which is responsible for running, building the plugin later.

Step 2 — Create the SimpleLanguage.java file

This class implements the Language base class which base class for all programming language support implementations.

Step 3 — Create the SimpleIcons.java file

We define all our icons in this class. You need to create a icons directory under the source resource directory and place a simple.png file there (refer to the screenshot below). This will be the icon for all our Simple type files.

For this article, I use Icons made by Freepik from www.flaticon.com which is licensed by CC BY 3.0.

File Structure

Step 4 — Create the SimpleFileType.java file

Step 5 — Create the plugin.xml file

We need to create a plugin.xml file under META-INF in source resources directory. This is the file which contains all of the details about our Simple plugin.

File Structure

Step 6 — Create the SimpleFileTypeFactory.java file

We also need to update the plugin.xml file. Add the fileTypeFactory extension to the extensions section so that the resulting plugin.xml file will look like this.

Step 7 — Run the plugin

In the Gradle Tool Window, you can find the runIde task. Double click and run this.

This will start a new Intellij IDEA instance with our plugin installed.

New IDEA instance

We create a new project to test file type association. It can be any type of project. For this example, I am creating a new Java project.

Now create a new file with .s extension. If you have done everything correctly, you will see the icon which we provided earlier as the icon of the new file.

Congratulations !!! You have successfully completed the first part of this tutorial :)

You can find the complete source code for this section of the tutorial at GitHub.

Stay tuned for the next article of this series :)

Part 2 — https://medium.com/@shan1024/custom-language-plugin-development-for-intellij-idea-part-02-f948a078dc81

--

--