What Happens on MPS Startup
This page looks behind the hood of the startup process of MPS 2021.1.4 and newer. For most parts, similar code executes for other MPS versions.
The application starts with Launcher.java ⧉, setting some IntelliJ-specific properties, such as the file watcher path and the platform prefix, and collecting the plugin paths when running MPS from sources.
It then calls Main.kt ⧉, where it sets flags about the execution environment, such as the headless mode or if the application is invoked from the command line.
The system properties are also loaded and populated with data.
BootstrapClassLoaderUtil#initClassLoader() loads the class loader. Afterward, MainImpl.kt ⧉ is looked up
and executed. It mainly redirects the application's initialization to the ApplicationLoader#initApplication ⧉ method.
The time from this method to ApplicationLoader.run
is called app initialization. Here, the command line arguments are
first processed: a special method looks for -Dkey=value
program arguments and stores some of them in system properties.
A task on the event dispatch thread initializes the GUI and loads system fonts. Plugins are also initialized
and loaded.
You can start MPS from MPS itself through MPSEnvironment.java or IdeaEnvironment.java from outside. EnvironmentConfig Both initialize both classes. It also lets you specify the plugins, macros, and libraries that should be loaded. In IdeaEnvironment#createIdeaApplication ⧉, some IntelliJ-specific properties are also set. Both environments can manage MPS projects (creating, opening, and closing them).
For the integration with the IntelliJ platform, MPSCoreComponents ⧉ plays an important role: it contains references to the following core components:
- MPS platform with the base class PlatformBase ⧉
- PersistenceRegistry.java as the core component implementation of PersistenceFacade ⧉. The PersistenceFacade represents a singleton registry of models, model root factories, find usages, and navigation participants. It also provides methods to transform strings to model refs/module refs/node IDs and vice versa.
- LibraryInitializer.java, which manages library contributions (loading, unloading, updating). It creates instances of SLibrary for each path RepositoryContributor#getPaths() returns. SLibrary tracks a path with modules inside. It listens to file system events and reloads modules from the disk if necessary. It is the layer between SRepository and SModule ⧉ in the repository hierarchy (as well as the project). The repository consists of library modules, project modules, and several special modules.
- ClassLoaderManager.java ⧉ is responsible for loading classes within MPS.
MPS Platform¶
The MPS platform contains so-called component plugins that are registered through PlatformBase:
- MPSCore.java ⧉, the core MPS functionality layer
- MPSProjectValidation.java ⧉, which provides validation code for project modules. It contains the following core checkers:
- The structure checker ⧉ inspects the structure aspect for errors (e.g., missing reference, properties)
- model properties checker implemented in ModelValidator.java ⧉
- Module checker ⧉, which shows errors in the logical view
- The constraints checker ⧉ inspects parent/child, can be root/ancestor, and property constraints.
- MPSMake.java ⧉, which provides the components
- MakeServiceComponent ⧉ gives access to the active facility to perform project make
- FacetRegistry provides methods for registering/unregistering and looking up facades ⧉.
- MPSTypechecking ⧉, which provides the components
- TypecheckingFacadeComponent ⧉
- LanguageScopeFactory ⧉
- TypecheckingBackend.java is used to install and uninstall TypecheckingProvider ⧉.
- MPSTypesystem.java ⧉, which provides the components
- TypeChecker ⧉
- TypeContextManager, a deprecated class that shouldn't be used anymore (use TypecheckingFacade ⧉ instead)
- MPSGenerator ⧉, which provides the components
- ModelGenerationStatusManager allows querying the generation status of models and listening to changes in the generated files through a ModelGenerationStatusListener ⧉.
- GenerationSettingsProvider manages the generation settings ⧉.
- TraceRegistry, the entry component for the generator trace ⧉ mechanism
- MPSFindUsages ⧉, which provides the components
- FindUsagesFacade ⧉, an effective (usually index-based) implementation of find usages routines.
- FindersManager ⧉
- MPSTextGenerator ⧉, which provides the component
- TextGenSettings, the settings ⧉ that are used by text generation
- MPSFeedbackPlugin ⧉, which provides the component
- FeedbackAspectRegistry, which manages the descriptors of the feedback language aspect ⧉
MPSCore¶
This class provides the following core components:
- LibraryInitializer, which manages library ⧉ contributions (loading, unloading, updating)
- PersistenceFacade ⧉, which represents a singleton registry of models, model root factories, find usages, and navigation participants.
- ClassLoaderManager ⧉, which is responsible for loading classes within MPS
- MPSModuleRepository is a repository with modules visible in MPS. It is used by the class ProjectRepository ⧉.
- LanguageRegistry ⧉ manages languages and their generators.
- ModelFactoryRegistry stores default associations between ModelFactory and DataSourceType ⧉ (many-to-many mapping). Examples of DataSourceTypes are the bundles' data source types .mps, .model, and .mpsr. The class also stores a mapping between model factory types and model factories, allowing users to replace the bundled persistence we provide.
- SRepositoryRegistry, which manages SRepository ⧉ instances (they are storages for modules)
- FacetsFacade ⧉ manages language facades.
- PathMacros manages path variables ⧉ and also some builtin macros such as USER_HOME, MODULE_DIR, PROJECT_DIR, APPLICATION_PLUGINS_DIR, and MODULE_WORKING_DIR.
- ExtensionRegistry ⧉, which manages extensions populated by classes loaded from compiled and deployed modules
- ConceptRegistry ⧉ manages concept descriptors.
- DataSourceFactoryRuleService ⧉, which is a service provider for defining own data source factories
- DescriptorIOFacade, which returns DescriptorIO ⧉ instances that are responsible for reading and writing descriptors to/from a file
- ModelsAutoImportsManager manages AutoImportContributor. Classes that extend this class can automatically add languages to a model. For example, TestsModelAutoImports ⧉ automatically adds the languages jetbrains.mps.lang.test and jetbrains.mps.baseLanguage.unitTest to test models.
- VFSManager is an entry point to access various file system protocols available in MPS. Virtual File System - IntelliJ Platform Plugin SDK ⧉ contains More information about VFS.
- ProjectManager manages MPS projects. You can receive events sent while opening and closing a project through a ProjectManagerListener ⧉.