CoreComponent¶
How to I start using MPS' Open API?
Specific Languages Blog — The simplest way to use MPS Open API
How to I get MPS core components from code?
From the console:
MPSProject p = ((MPSProject) #project);
Platform host = (Platform) p.getPlatform();
#print host.findComponent(MakeServiceComponent.class);
How to I convert between different Project classes?
Use the class ProjectHelper.
What interesting MPS utility classes can I use in my code?
- DirUtil - directory related utilities
- MatchingUtil - check if two nodes match
- SubtypingUtil - subtyping related utilities
- CopyUtil - utility for copying models, nodes etc.
- FileUtil - file related utilities
- JavaNameUtil utilities related to java naming
- NameUtil - name related utilities such as pluralizing or escaping strings
- CopyPasteUtil/TextPasteUtil - copy paste related utilities
- ActionUtils - action related utilities; can be used to execute an action programmatically
- NewModuleUtil - utilities related to created new modules such as creating solutions or languages
- TemporaryModels - utilities for creating temporary models
- UIUtil - utilities related to the Intellij UI such as checking for dark mode (isUnderDarcula()).
- PathManager/PathManager - classes for getting all kind of paths such as the plugins folder or the log folder.
I want to change something inside a SModule such as adding a dependency but can't find the right method.
Try casting it to AbstractModule first.
How does class loading work in MPS?
See this comment, Dependencies and Classpath in MPS and classloading issues.
Is there a way to start two instances of MPS, each with its own cache/state?
You can create a copy of you MPS installation and edit the idea.properties file in the bin directory. Changing idea.system.path should allows you start a second instance with dedicated caches/state. If you don’t want to share any configuration also update idea.config.path.
How do I get an icon for a concept?
Call GlobalIconManager.getInstance().getIconFor(concept)
.
Where can I find builtin icons?
IntelliJ IDEA icons are declared in the class AllIcons. MPS icons are declared in the class MPSIcons.
I have settings that I want to save globally1.
Preferences can be only used at the project level. Use the workaround described in this answer
or save your values in the global IntelliJ IDEA Registry.
More information about the Registry can be found in this Stack Overflow post.
It can also be shown programmatically by calling new RegistryUi().show()
.
How can I call make or rebuild?
Use need to use MakeActionImpl. Example usuages can be found in the same model.
How do I work with temporary models?
try {
undo-transparent command with this.mpsProject.getRepository() {
tmpModel = TemporaryModels.getInstance().createReadOnly(TempModuleOptions.forDefaultModule());
tmpModel.addRootNode(type);
TemporaryModels.getInstance().addMissingImports(tmpModel);
}
// do something with the node
} finally {
undo-transparent command with this.mpsProject.getRepository() {
tmpModel.removeRootNode(type);
TemporaryModels.getInstance().dispose(tmpModel);
}
}
How to I add widgets to the status bar? (memory indicator, save transient models...)
Have a look at this answer. Make sure to call this code from a project plugin.
How to I display a message in the status bar? (left bottom corner)
Note: The message might not be visible by calling from the console, because the rebuild of the model already shows a message:
WindowManager.getInstance().getStatusBar(ProjectHelper.toIdeaProject(#project))
How can I register an IntelliJ extension?
Find the interface you want to add an extension on this page.
The corresponding interface has a static field EP_NAME
. If the interface is implemented in Kotlin it might have a static field Companion
with a getEP_NAME()
method. Extend this interface (EX) and register it through the extension point.
Example: Interface.EP_NAME.getPoint().registerExtension(new Ex())
How can I add a status bar widget?
Implement the interface StatusBarWidgetFactory
and register it through the StatusBarWidgetFactory.EP_NAME extension point.
How can I react to selection changes in the editor?
editorContext.getSelectionManager().addSelectionListener(new SingularSelectionListenerAdapter() { ... })
How to I add model imports and used languages programmatically?
Specific Languages Blog — Adding model imports and used languages programmatically
How do I run MPS code from the command line/CI?
- Specific Languages Blog — Running MPS code from command line
- Specific Languages Blog — Running code in MPS on CI
How can I render a node as text?
Specific Languages Blog — Rendering a node as text
How can I associate additional information with a node?
Specific Languages Blog — Associating additional information with a node
How does shrinking of absolute paths work?
Specific Languages Blog — Shrinking of absolute paths