Adding Comments in MPS (including answer by Vaclav Pech)

Is there a way to add comments?
a. Comments in the Projectional Editor of the Concepts/constrains/etc.
    • For documentation / explanation
    • For commenting out some "code" during development
b. Comments which will appear in the sandbox Node?
    • For guiding the user

Answer (by Vaclav Pech):
In language definition languages comments are allowed only in a few places, e.g. to describe actions, key maps or action maps and are typically labelled as “description". You can comment out snippets of BaseLanguage code inside blocks of BaseLanguage code (concept functions), just like you would in any Java methods, but you cannot comment out a whole action-map entry, for example. This is currently not supported, I’m afraid.
If your languages should support comments in user code, you need to explicitly add support for this into your languages. See https://confluence.jetbrains.com/display/MPSD32/Documentation+comments and https://confluence.jetbrains.com/display/MPSD32/Commenting+out for inspiration.
4 comments
Hi!
Just wanted to add that a feature is planned for the next release which will allow to comment out nodes in a generic way, and possibly add textual comments to any nodes, without language author specifically enabling it in their language.
1

Hi,

is it still the case that documentation comments are not supported in BaseLanguage, or has there been some progress?

Also, what about comments in class/interface bodies? In blocks of statements, after typing "//" on an empty line, that line turns into a comment. However, this does not work inside a class or interface body. As a workaround, for classes I use `{ ... }` blocks containing comments:

    class Foo {

        {

            // comment

        }

    }

but this doesn't work for interfaces.

1

See https://confluence.jetbrains.com/display/MPSD20181/Generic+placeholders+and+generic+comments

BaseLanguage is, however, restricted and only allows Java-style comments to be attached to fields or methods.

1

I was interested specifically in BaseLanguage, and I didn't see an option to add doc comments to fields or methods or classes. I got my answer from Vaclav in an in-person conversation: I just needed to import the language `jetbrains.mps.baseLanguage.javadoc`, after which the Intentions menu (Alt+Enter) offers to "Add Documentation Comment". For fields and methods, it is also possible to type `/*` on the preceding empty line and then trigger autocomplete (Ctrl+Space), which converts the line into a doc comment.

0

Please sign in to leave a comment.