The intentions menu is flat and can get very long. The mbeddr platform provides a mechanism to split the intention menu into groups which helps somewhat. But even with groups the menu can get very long. What can you do if you want to add some hierarchy to it? MPS does not offer straightforward support for submenus in the intention popup menu but we can use the IDEA Platform API to emulate them.

First, we need to rewrite intentions as actions. If your intentions are parameterized you can use parameterized actions:

Then we create an action group for the submenu with the new actions:

Next comes the action to show this group in a popup menu using JBPopupFactory class from IntelliJ Platform:

Finally, we add the action to ActionsAsIntentions group (we have to use another action group for that):

You may be wondering why we don’t add the submenu group to the ActionsAsIntentions group directly and skip MyGroupAction. This approach does not work because the ActionsAsIntentions group hierarchy is always flattened and added to the intentions menu as a long list of actions.

The end result is not quite the same as having a hierarchical menu because the original menu disappears when the user chooses the submenu action, but it is quite close. The video below shows the menu in action.