Child pages
  • Commenting out nodes

Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


Commenting out/uncommenting nodes from code

The CommentUtil class  class from jetbrains.mps.editor.runtime can  can be used to comment out and uncomment nodes from code, such as actions, intentions or key or key maps. This gives you options to further customize the behavior of commented out nodes.

The CellAction_CommentOrUncomment and its inheritors class come from the same package. They give you the way to simply comment the node and restore the selection or uncomment the node if it is currently commented.

The Comment editor action

The response to the comment/uncomment action can also be customized on the node level. You can set the handler for for COMMENT action in the cell's action map:

Image RemovedImage Added

For example, if we want to prevent the user from commenting out conditions in the robot's Kaja Kaja While statement statement, we attach the above action map to the While editor's cell representing the the condition:

Image RemovedImage Added

Since can execute block of the COMMENT action handler returns false, the COMMENT action will not be executed on the %condition% cell. MPS will try to execute the COMMENT action on its parent cell, and then the whole While statement will be commented outthe COMMENT action is customized it will do what is indicated.

The action will work only if the condition node is selected.

Since we create the CellAction_CommentOrUncommentNode with the node as the parameter, where the node is the While statement, the action will process the While statement:

1) If it is not commented, the action will comment it out.

2) If it is commented out, the action will uncomment it.

Thus the commenting of the condition will be disabled.