Using MPS inside IntelliJ IDEA

Skip to end of metadata
Go to start of metadata

We are going to show how to use MPS languages inside IntelliJ IDEA in this document. You may also like to check out the screen-cast covering this topic.

Note: Please make sure you have IntelliJ IDEA 11.0.2 or higher installed. Both Community and Ultimate Edition would work.

Get the MPS core IntelliJ IDEA plugin

Download the MPS core IDEA plugin from the MPS download page or install it directly using IntelliJ IDEA's plugin manager. If installing manually, the downloaded plugin zip file must be unzipped into the IDEA's plugin folder.

  • Windows and Linux: typically USER_HOME/IDEA_version/config/plugins or IDEA_HOME/plugins
  • MacOS: ~/Library/Application Support/Idea_version/ or IDEA_HOME/plugins

The folder should be holding three new directories and a single new jar file once the core plugin has been installed and so it should look something like this:


This will enable MPS and the core set of languages to be available inside IntelliJ IDEA once you restart it.

Turn MPS on and off

The Plugin Manager in IntelliJ IDEA should now list several MPS plugins, which you can turn on and off as needed:

Try BaseLanguage inside IntelliJ IDEA

You can now enable the MPS facet for your IntelliJ IDEA projects:

The facet offers several configuration points, but you most likely want to stick to the default settings for your first experiments.

Adding the MPS facet to a project will create a models node in the Project View and allow you to create MPS models:

When creating a new model, you have to specify its name and choose one of the available model Kinds through the Create New Model dialog:

Each model Kind in this case represents a preconfigured set of used languages for the model. This is a convenient shorthand that still allows you to tune the list of used languages manually at any time through the Model Properties dialog by pressing Alt+Enter on the model node inside the Project View: The list of Kinds is currently set to contain only these two options (Empty and Java), but will be configurable in the future releases.

Right-clicking on a model will display the imported models and used languages:

The MPS models let you create new nodes from the imported languages the same way you would do it in MPS itself: Model Nodes in the Project View represent the content of MPS models and just like in MPS they are similar to java packages. You can create model elements (Roots) in them:

Similarly to when we were creating new MPS models, you give each root element a name and a kind, which now means its MPS Concept:

The root nodes are displayed in the Project View and look very similar to how other resources and files look in IntelliJ IDEA. The projectional editor for a root node can be opened by double-clicking on the root node or by pressing F4.

Code generation

The code process of MPS models is tied to the IntelliJ IDEA's make/rebuild project actions and so will be triggerred automatically.
It's possible to configure where to store the generated source code. This is configured through the MPS facet settings dialog. There are three options you can choose from:

  • The generated code stays in memory only. It will be available during the compilation process only and never saved to disk at all
  • It can be saved into another source folder of this module
  • It can be saved into any other directory wherever on the disk

Install the language plugin

Now you probably can't wait to try out your own language inside IntelliJ IDEA. All you need to do is to unpackage the plugin zip file into the same IntelliJ IDEA's plugins folder that we unzipped the core plugin into earlier:

Additionally, many of the plugins have been shared through the IntelliJ IDEA plugin repository and so can be comfortably downloaded through the IDEA's plugin manager.

After you restart IntelliJ IDEA, you will be able to add your language(s) that came through the plugin to the list of used languages:

This should be enough to enable your custom language(s) for use inside IntelliJ IDEA.

Adding runtime libraries

Your languages will typically come with runtime dependencies on other languages or solutions. Although they typically come bundled as jar files inside the plugin zip file, they need to be imported individually following the standard IntelliJ IDEA's way as. Check out the following screen-shot for guidelines:

You'll most likely search for the libraries under the particular language plugin folder in the IntelliJ IDEA's plugins location.

MPS confiuration options

Just like MPS itself, the MPS plugin can be configured and customized using the Settings dialog, which you can invoke through the menu, a toolbar or using a keyboard shortcut (Control + Alt + S / Cmd + ,). MPS has added a couple of configuration screens to the IntelliJ IDEA's Settings dialog, which allow you to configure several aspects of how MPS behaves.

 

Configure the generator

Additionally, you need to make sure the Use external build flag in the IDEA Compiler settings is turned off, otherwise you won't be able to rebuild your project. 

Get a head start

You may use the attached Sample Java Extensions language plugin for your first experiments. This is an IntelliJ IDEA language plugin that contains some of the languages from the SampleJavaExtensions sample project that comes with MPS distributions. Just unzip it into your IDEA's plugin folder (provided you have installed the MPS core plugin) and play with the languages. Also, do not forget to include the four runtime libraries in your IDEA project (as shown above in the "Adding runtime libraries" section).

Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.