As we have seen when discussing Typesystem vs constraints and as Kolja Dummann says in his MPS Community Meetup presentation, it is often useful to let users write invalid code. This gives users an easy to use place to leave feedback: “Hey, the DSL tells me that ‘foo’ is invalid here, but I actually should be able to write that.”
Sometimes it makes sense for a user to leave a textual comment at some place, say “I want to be able to write ‘foo bar baz’ here but the IDE doesn’t let me”. However, changing your model to support comments in addition to “real” code is difficult. You need to change the structure to allow multiple concepts in place of one, then you have to deal with the resulting worse editing experience: where MPS could automatically create an instance of a proper node it would now start asking you whether you want to create the real node or the comment. Not only that, but now you have to also deal with ignoring the comments when you generate code or otherwise analyze the DSL models.
Overall, it looks like too much pain for rather unclear gain: the users may never need to leave any comments in that particular place.
As it turns out, MPS has a great feature for entering these comments that does not require you to change your model at
all. It is not widely known, especially among language users, but you can add a piece of text anywhere you can enter
multiple items. This feature is called generic
comments and the way it works is you
simply press Ctrl/Cmd+Shift+Enter
where you would normally press Enter
. Pressing that key combination adds a blank
line instead of a new regular item. If you now import (use) language jetbrains.mps.lang.text
, you can press [
and the blank line will turn into a comment node, accepting arbitrary text.
Best of all, the text you enter is stored in a node attribute so it will stay out of the way of most pieces of logic you may have that work with the model.
If you provide your users with a devkit that they should be using in their models you can add jetbrains.mps.lang.text
to it so that they will have one less step to take. Be sure to do this and educate your users about this functionality.
The easier it is for them to give you feedback, the better your DSL and the tooling can become.