A black and white image of the author Kolja Dummann

Skadi Cloud Gist.

Share MPS code snippets on the web.

With the projectional editor of JetBrains Meta Programming System (MPS) sharing code has always been kind of a challenge. Code is often shared via git repositories, screenshots, or alike. This doesn’t allow you to “see” the code in the browser and has a lot of overhead to access it. You need to clone the repository, open it with the correct MPS version, and then take a look at it. Especially for smaller snippets, used to illustrate a problem, provide the solution to a problem or just share a best practice this isn’t practical.

In the community, we have developed workarounds for this. We share screenshots of the editor, use the link feature of MPS to point each other to existing implementations, or copy the text of the editor and share it. While sharing a link works reasonably good when both parties happen to have access to the code where the link is pointing the other options often don’t. When sharing a screenshot, you need to type what you see into your editor again. Retyping can be cumbersome for large code fragments and sometimes it’s not that straightforward because of ambiguities in the code. The famous three different Project classes or interfaces in MPS are one example here. If the text from the editor is shared the text can only get imported if the language it is written in has support for parsing text into MPS models. This use-case works ok for ´baseLanguage`, the Java implementation of MPS, but other languages rarely support this.

I’m personally a big fan of Githubs Gist feature, where you can upload code snippets and a description and then share them as a link or even embed parts of them. From my early days in MPS, I wanted to have something similar. The idea itself is quite old at some point Alex, Joao, and I even hacked a rough prototype during a hackathon. That prototype was never put to use anywhere.

After building the skadi.cloud demo to show what can be done with projector, MPS, and container applications, I finally wanted to make this idea reality. You can find it at gist.skadi.cloud. While this doesn’t share any code with the previous prototype, in fact, it’s a totally different technology stack, it can be seen as the spiritual successor. The web interface is still in its very early phase and will change in the future.

How does it work? The whole thing has two parts: a plugin for MPS and a backend. When creating the gist the plugin does two things: it takes a “screenshot” of the editors you want to share. Then it sends the screenshot along with your metadata like title and description to the server, but it also includes the AST of what you share. This allows others to import the exact same “code” without typing. The backend then stores this information and makes the gist accessible on the website. On the website, users can see the “screenshot” of the code and then decide to import it into their MPS via the plugin. Here is a demo video of it in action:

If you are interested in using it, you can get the MPS plugin here. The plugin is currently available for MPS 2021.1 but 2021.2 will be supported soon. I don’t plan to support older versions of MPS at the moment.

If you like to support an older version of MPS you can actually do that because the whole project is open source! The other reason for open sourcing was: models often contain information you can’t easily share with a third party so you can run your own gist instance. The MPS plugin and the server are available under the MIT license. You can find the code here. I will be talking about the inner workings in a dedicated blog post later next week.

The plugin support choosing the backend address. The server includes a Dockerfile to build a container that you can run on your own infrastructure. I also include the kubernetes configuration for the public instance. Right now the server isn’t built with many different use cases in mind but I’m happy to accept your contributions to make it fit your needs. I haven’t created documentation for running and configuring the container at the moment. Feel free to ask questions in Github Discussions or help contribute your experience as documentation.

If you like to contribute, no matter if by writing code or other means, take a look at the contribution guide. No code contributions are highly welcome e.g. testing use cases in your environment, new feature ideas, or enhancing the documentation.

One last, maybe unusual thing: You can now sponsor me on Github via the Github sponsor program. I’m building and running these projects in my spare time and with my own money. While sponsoring isn’t expected nor required it is greatly appreciated. It helps me to pay for the costs but most importantly it’s a huge motivator for me to keep doing these things!

If you liked the content consider subscribing to the email newsletter below. The newsletter delivers all posts directly into your inbox. For feedback on the topic feel free to reach out to me. You can find me on Twitter @dumdidum or write a mail to kolja@hey.com.