MPS plugin for IntelliJ IDEA
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 propagated into the Messages View alongside all other compilation problems. You also have the possibility to navigate to the corresponding model elements by clicking on the displayed error:
<create screenshot here>
It is not yet possible to directly run a program represented by an MPS node - the generated code should be used to execute the program instead. However, we've already implemented the ability to set a breakpoint directly inside the DSL code and so the IntelliJ IDEA debugger will be stopped in the appropriate place allowing you to explore the stack trace and the variables:
When comparing versions or resolving conflicts in MPS models, you can rely on the MPS structural diff/merge tool, 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 the IntelliJ IDEA plugin and you can invoke them with the usual keyboard shortcuts (e.g. Ctrl+L for importing a language):
The MPS plugin distribution contains 4 separate plugins 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 separate plugins and potentially distributed together with the MPS plugins to deliver your own powerful DSL features to the IntelliJ IDEA developers.