Writing an MPS Plugin with Kotlin
When you use Kotlin to write an MPS plugin, the guidelines for the IntelliJ Platform SDK ⧉ apply.
Folder Structure¶
The folder structure should look like this:
├── build.gradle.kts └── src └── main ├── kotlin └── resources └── META-INF ├── plugin.xml └── pluginIcon.svg
build.gradle.kts¶
The file build.gradle.kts should look something like this:
The Gradle plugin org.jetbrains.intellij is needed for the IntelliJ plugin development, org.jetbrains.kotlin.jvm is needed for Kotlin support. We also add the itemis repository for the MPS dependencies. The dependency section contains dependencies for Kotlin and MPS. The available MPS dependencies are in the group JetBrains on mvnrepository.com ⧉. The rest of the code is boilerplate code for setting the correct versions.
plugin.xml¶
The file plugin.xml ⧉ is the plugin configuration file and usually is automatically generated by the MPS build language. In this file, you have to register, for example, tool windows, settings, and actions. Look at existing plugin.xml files ⧉ to figure out how they work.
Don't forget to add dependencies to the MPS plugins in this file:
Links to Sections in the Documentation¶
- Actions ⧉ extend the class AnAction
- Tool window ⧉
- Preferences ⧉
- Application plugin ⧉
- Running tasks once ⧉
- Project plugin ⧉
For everything else, look at the extension point and listener list ⧉.
Building the Plugin¶
When ready, you can build the plugin by executing ./gradlew buildPlugin
. Gradle IntelliJ plugin ⧉ explains all the other tasks. Now there should be a folder build/distributions
which contains the zipped plugin that you can install through the MPS plugin manager.
Running the Plugin¶
Open the file build.gradle.kts
in the ide-plugin
folder and change the intellij
block to use a local
path, and turn off the instrumentation of the code, e.g.:
Then you must ensure that you set the system variable idea.platform.prefix
to 'Idea'.
Workaround: Create a file with extension .sh or .bat in the bin folder of the MPS installation with the following content: -Didea.platform.prefix=Idea
.
You can now open MPS with the plugin installed by calling ./gradlew runIde
.