MPS 2.5 can be run as a plugin for IntelliJ IDEA enabling MPS-based DSLs to be used directly in a Java IDE and so interoperate , interoperating tightly with other elements of the project. This document will guide you through the details of how to setup IntelliJ IDEA so that you can use the MPS plugin aongside your Java code.
Integration with the IntelliJ IDEA Project structure.
To enable the MPS features inside a particular java project module, you simply add the MPS facet to the module through the Module Settings dialog:
We recommend you to create a dedicated Java Source Root folder to store the MPS model files. Use the Add Model Root button on the Soures tab of the MPS Facet configuration page:
Model root folders look just like any other source roots in IntelliJ IDEA. In addition to the the regular source roots it is possible to create MPS models in Model Roots:
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:
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:
Although you need MPS in its entirety to create languages, IntelliJ IDEA represents a convenient additional channel for DSL distribution.
Enabling MPS inside a Java module is as simple as adding the MPS facet to it. Just like in MPS you can create models, import any MPS languages and start instantiating the root nodes. The root nodes are displayed in the Project View and look very similar to how other resources and files look in IntelliJ IDEA together with the other project sources and files. The projectional editor for a root node can be opened by double-clicking on the root node or by pressing F4:Image Removedthe root nodes opens directly in IntelliJ IDEA so all your code stays within a single IDE.
The code generation 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
All . You hit Compile in IDEA and your MPS code gets generated and compiled as well. No need for extra steps.
The generation-time errors are prorated propagated into the Messages view just like any View alongside all other compilation problems with . You also have the possibility to navigate to the corresponding model elements by clicking on the displayed error:
<create screenshot here>
Unfortunately it's not possible to run program using MPS nodes right node - generated code should be used to execute program, but it is possible to set a breakpoint directly inside DSL so IDEA debugger will be stopped in appropriate place to explore stack trace and variables:
Just like in MPS you can use Image Added
When comparing versions or resolving conflicts in MPS models, you can rely on the MPS structural diff/merge tool working upon MPS models and rendering , just like in MPS. The tool will render the model content in a domain specific rather then the persistence-specific way:
Most of the common MPS actions/refactorings/intentions are available in IDEA plugin from now and accessible with usual shortcuts like Ctrl+L for importing language:
The MPS debugger has been integrated into IntelliJ IDEA as well. When debugging your Java code you can set breakpoints directly inside the DSL code and so the IntelliJ IDEA debugger will be stopped at the appropriate place allowing you to explore the stack trace and the variables.
The MPS plugin distribution contains 4 separate plugins now, so some at the moment. Some of the MPS functionality can be easily switched off by disabling the corresponding plugins in the Plugins configuration dialog. At the same time, user-specific DSLs can also be packaged as a separate plugins and potentially distributed together with the MPS plugins to provide IDEA developers with deliver your own powerful DSL features to the IntelliJ IDEA developers.