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 12.1.4 or higher installed. Both Community and Ultimate Edition would work.
Download the MPS core IDEA plugins from the MPS download page (EAP) 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 zip file holds several MPS plugins, three of which are essential:
- mps-core - holds the core MPS functionality
- mps-java - enables BaseLanguage and its extensions
- mps-vcs - allows VCS for MPS models in Intellij IDEA
After installation, the plugin directory 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.
The Plugin Manager in IntelliJ IDEA should now list several MPS plugins, which you can turn on and off as needed:
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's module will create a models node in the Project View and allow you to create MPS models. If not, just create one on the Sources tab:
You need to mark it as a Model Folder (the icon next to the models folder should turn blue):
The final step is to mark the models folder as a Sources directory of the module:
Once the MPS facet is configured and has one or more Model Roots marked Model as well as Sources Folders, you can create models in them:
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 F4 or 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.
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 a configured source folder of this module
- It can be saved into any other directory wherever on the disk
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.
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 as module dependencies into IntelliJ IDEA.. The MPS facet does that automatically once you add a language with a runtime dependency.
|In case you needed to add run-time libraries manually, the real location of these dependencies (jar files) is under the particular language plugin folder in the IntelliJ IDEA's plugins location.|
The MPS IDEA plugin integrates your MPS code tightly into the rest of the Java project. MPS code will seamlessly participate in IDEA's build and make, you can cross-navigate to usages or definitions between Java and BaseLanguage as well as refactorings will correctly include all the sources.
MPS gives you a convenient option to quickly convert Java code to BaseLanguage and migrate it into an MPS model. Just right-click on the desired Java package and select Convert Java to MPS.
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.
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.
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).