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 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:
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:
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
All generation-time errors are prorated into the Messages view just like any other compilation problems with possibility to navigate to corresponding model elements:
<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 structural diff/merge tool working upon MPS models and rendering model content in domain specific rather then 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:
MPS plugin distribution contains 4 separate plugins now, so some MPS functionality can be easily switched off by disabling corresponding plugins in the same time user-specific DSLs can be packaged as a separate plugins and distributed together with MPS plugins to provide IDEA developers with your own powerful DSL features.