MPS Plugins and introspection

Hi, I am considering to write a plugin for MPS to perform some manipulation on the models present in a project. Is some documentation available? Do you have any suggestion?

Thank you,

Federico
14 comments
Hi, Federico,

Some documentation on MPS is available here
http://confluence.jetbrains.net/display/MPSD2/MPS+User%27s+Guide
If you have questions not mentioned there, please feel free to ask - we can write documentation for the most interesting parts in MPS core.

Regards,
Mihail
0
Hi Mihail,
thank you but it seems to me the documentation for users. There is any documentation about the internals and about writing plugins for MPS?

For example a plugin to look for nodes of a given type and with certain characteristics in the whole workspace?

Federico
0
Suppose you want a new menu item which will perform your algorithm on all the nodes in project. In this case, all you need to add a menu item is written here:
http://confluence.jetbrains.net/display/MPSD2/Plugin#Plugin-Actionsandactiongroups
So, you add an action and place it into some menu. Then you need to get all the modules of the current project from the action. Just add a context parameter to an action - and here's current MPSProject.

The next part is not described in the documentation, but it's quite simple - the project has its modules, and each module has its "own" models (project.getModules(), IModule.getOwnModelDescriptors(), SModelDescriptor.getSModel()). So, you get all the models in your project. Then you cast the SModel instances you got to MPS type "model" and you can further start using the smodel language.

The next part is working on the "below-model" level (smodel language), and it's partially described here
http://confluence.jetbrains.net/display/MPSD2/SModel+language
but IMO it's quite intuitive if you read the first chapter of the documentation
http://confluence.jetbrains.net/display/MPSD2/Basic+notions
http://confluence.jetbrains.net/display/MPSD2/MPS+project+structure
so you can continue looking at it just by using completion menu.

If you ave further questions, need an example etc., feel free to ask.

Regards,
Mihail
0
We haven't documented the above-model level, because there are some reasons for that:
1) now we don't have a public API on this level as we change it very often
2) we plan to reorganize the inner part of how MPS stores models, so the API will be changed, and I suppose that's the point where we could stabilize it.
3) the language authors don't typically need to go above the model level
0
Hi Mihail,
thank you very much.

I am at the very beginning:

I select from the Menu Go To -> Go to Model, and I search for “jetbrains.mps.ide.actions”.

Then I select inside actions the folder Menu, ProjectPane, Model, Action and I create a new  jetbrains.mps.lang.plugin.Action.

When I open the new created Action I have this message:
“Warning: the node is in a packaged model. Your changes won’t be saved”

The new created Action is not editable (I am not able to set a name).

How can I create an Action and save it?

(As soon as I understand what are the steps I am trying to read a "for-very-dummies" tutorial)

Regards,
Federico
0
Ok, I think I understood:
  • I have to create a Group and add it to an existing group
  • Then I create an Action and insert it into the group
0
Sure. In 2.0.x you can do this only in the "plugin" model of a language (you need to create a new one), in forthcoming 3.0 you could be able to do it outside of a language.
0
I am now also writing a Tool :) I am using the same API to navigate the nodes but I now get an error because I am trying to access nodes not into a "read action".


Error during dispatching of java.awt.event.MouseEvent[MOUSE_RELEASED,(988,621),absolute(980,613),button=1,modifiers=Button1,clickCount=1] on frame0: You can read model only inside read actions
jetbrains.mps.smodel.IllegalModelAccessError: You can read model only inside read actions
jetbrains.mps.smodel.IllegalModelAccessError: You can read model only inside read actions
 at jetbrains.mps.ide.smodel.WorkbenchModelAccess.doAssertLegalRead(WorkbenchModelAccess.java:98)
 at jetbrains.mps.smodel.ModelAccess.assertLegalRead(ModelAccess.java:163)
 at jetbrains.mps.smodel.SNode.getConceptFqName(SNode.java:1302)
 at jetbrains.mps.smodel.SNode.getConceptDeclarationNode(SNode.java:1345)
 at jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations.getConceptDeclaration(SNodeOperations.java:591)
...

How can I create a read action? Should I start another thread?
0
Other thread is not necessary.
To create a read action, just type "read action". Read action is a statement. To change models, use "write action". It can be started from any thread, too.
0
I just wrote a "for dummies" tutorial about creating an Action with a screenshot for each step. I don't know if it can be helpful to someone, just in case you can find it at: http://www.federico-tomassetti.it/tutorial-how-to-add-an-action-to-the-jetbrains-metaprogramming-system/

I plan to write a second part implementing the export functionality in the action code to produce some XML form of the models.
0
Thanks a lot!
Added a link to plugin documentation page, here:
http://confluence.jetbrains.net/display/MPSD2/Plugin
If you don't mind.

If you write some other posts and howtos on mps, I'll be glad to reference them from our pages where appropriate.

Regards,
Mihail
0
It seems that in MPS 2.5 Tools work in a different way: creating a Plugin aspect I don't have anymore the option to create Tools or Action. There is by chance any update to the documentation?

EDIT: they are just moved in a sub-menu. By the way when I create a tool it does not automatically appear in the list of tools... I don't know how to start it.
0
You can check this document:
http://confluence.jetbrains.com/display/MPS/Migration+to+MPS+2.5, "Use separate Plugin Solutions to hold all platform-specific.." part

In general. you should create separate solution holding all platform-specific aspects like Actions/Tools/..
0

Please sign in to leave a comment.