MPS 2021.1 Help

Suppressing Errors

One of very effective ways to maintain high quality of code in MPS is the instant on-the-fly code analysis that highlights errors, warnings or potential problems directly in code. Just like with other code quality reporting tools, it is essential for the user to be able to mark false positives so that they are not reported repeatedly. MPS provides two mechanisms to suppress errors preventing them from being shown in editor and Model Checker tool.

 

The first is the general one that can be utilized by language developers. When designing a language extention or embedding existing language into the new one there can appear some places which are considered as errors by the checker of existing language but in fact are valid in terms of languages' combination. In such cases false errors can be suppressed by implementing the ISuppressErrors interface by the binding concept of the new language. Another place where this feature is also useful are the generators, since type errors, for example, are sometimes unavoidable in the templates. By default, if some concept implements the ISuppressErrors interface, all language issues on this node and all its descendants will be hidden. For example, comments in BaseLanguage implement ISupressErrors. Additionally, if a node has an attribute of a concept that implements ISuppressErrors, issues in such node will be suppressed too. It is also possible to suppress issues selectively, defining certain descendants in which issues should be suppressed and kinds of such issues. Customization can be implemented by overriding the boolean method suppress(ReportItem) of the ISupressErrors interface.

 

The second mechanism is implemented as the special case of the first one but is intended not for language developers but for the users of the languages. If some checker is known to issue false positives, user might want to mark these places in his model. Though language developer can make such possibility part of the language, MPS has a convenience default implementation of an ISuppressErrors node attribute called SuppressErrorsAttribute. It can be applied to only those nodes that are instances of ICanSuppressErrors.

An example of using the SuppressErrorsAttribute attribute and the corresponding intention.

There are three errors in editor, two of them are about string literals:

Suppress1
 

BaseLanguage Statement implements ICanSuppressErrors, so the user can apply intention to suppress either this very kind of errors (string literals) anywhere within the statement or every typesystem errors:

Suppress2

Now the suppressed errors aren't highlighted any longer, but there is a newly added cross icon in the left pane.

Suppress3

After suppressing one kind of errors, other kinds can be suppressed as well.

The suppressing attributes can be removed by applying the corresponding intentions or by pressing the cross:

Suppress4

Last modified: 08 March 2021