"Suppress" comments

Hi,

Is there an easy/recommended way of respecting the "Suppress" comments within a daemon stage process?

Do i need to actually detect them myself or is there a "IsSuppressed<THighightingType>(Range ...)" method?

Cheers,
Chris

11 comments

I found something in agentsmith's error report:

We had the same problem our plugin using the disable / restore comments and recently discovered a solution. Maybe the solution will work for you too.

If you implement the check using a "ProblemAnalyzer" instead of a "DaemonStage" and "DaemonStageProcess", then the infrastructure from ReSharper automatically implements the disabling for you.

To do this your ProblemAnalyzer class must have an attribute "ElementProblemAnalyzerAttribute ". There is a generic base class class "ElementProblemAnalyzer", which you can use.

In addition I think the Highlighting class needs to be marked with ConfigurableSeverityHighlightingAttribute. The Id used for the Highlight is the identifier that will be used in the disable / restore comments.

Coud someone comment on this, please?

What is the proper way to make disable/restore comments work?

0

It's a bit of a co-operative thing. The highlighting consumer has no support for comments - it will always add the highlight it's given.

Instead, you need to call one of the AddHighlighting extension methods on IHighlightingConsumer, as defined in CSharpHighlightingConsumerExtension (and friends for other languages). These call into the AddHighlighting extension methods defined in the language neutral HighlightingConsumerExtensions class. This class will check the severity of the highlight, and if the highlight is to be added inside a comment block, or a generated code block, and only add the highlighting when appropriate.

0

citizenmatt wrote:

This class will check the severity of the highlight, and if the highlight is to be added inside a comment block, or a generated code block, and only add the highlighting when appropriate.

I am not sure, if we are talking about the same issue.
The problem is: who is responsible for handling suppression of custom higlighting using comments in the code (like ReSharper disable ID).

Example:
Plugin AgentSmith has PublicMemberMissingXmlCommentHighlighting class which has SEVERITY_ID = "PublicMembersMustHaveComments".
It should be possible to disable this highlighting with:

// ReSharper disable PublicMembersMustHaveComments


but it doesn't work.
Sometimes I see "Suppress xxxx with comment" and it even adds ReSharper disable PublicMembersMustHaveComments, but the highlighting is still active.

So the theory is, that we should use "ProblemAnalyzer" instead of a "DaemonStage".

0

Yep, this is the same issue - the extension method I mentioned will look to see if any comments have been added to create regions where certain IDs should be ignored. If the highlight is to be added in one of these regions, it is ignored, and doesn't get added.

This will work with a daemon stage or a problem element analyser - they both use IHighlightingConsumer. (In fact, the problem element analyser infrastructure is implemented as a daemon stage)

0

Ok, thanks for help!
Now I know what I should look for.

ProblemAnalyzer has direct access to IHighlightingConsumer, that's why it might work.
On the other hand, DaemonStageResult only returns ICollection<HighlightingInfo>, so I must figure out, how to get IHighlightingConsumer from IDaemonStageProcess implementation.

0

Ah, good point. You can create an instance of DefaultHighlightingConsumer, which gives you the IHighlightingConsumer to call the extension method with. This will collect the highlights, and you can then call new DaemonStageResult(consumer.Highlightings) in order to pass to the committer in IDaemonStageProcess.Execute.

0

Thanks!

Which method should I call? Or maybe it doesn't matter?

public static class HighlightingConsumerExtension
  {
    public static IHighlightingConsumer AddHighlightings(this IHighlightingConsumer consumer, IFile file, IEnumerable<HighlightingInfo> highlightings);
    public static void AddHighlighting(this IHighlightingConsumer consumer, IHighlighting error, DocumentRange range, IFile psiFile, Severity? overridenSeverity = null, string overridenHighlightingAttributeId = null, OverlapResolveKind? overridenOverlapResolve = null, int? overridenOverloadResolvePriority = null);
    public static void AddHighlighting(this IHighlightingConsumer consumer, IHighlighting error, IFile psiFile);
  }
0

It doesn't matter. The two methods with the smaller number of arguments end up calling the one with all the args, and it's this one that does the work.

0

Thank you very much.
I rewrote Agent Smith's highlightings code and now it supports suppression by comments.
Cool!

The only little weird thing is, that if the problem has Hint severity, ReSharper doesn't show suppression by comment option, but it respects comments placed manually.

0

That's right, we don't offer to suppress hints. I think that's because they're hints, and unobtrusive - they don't appear in the error stripe on the side of the document, so you can still get the green tick without acknowledging the hint. Also, suppressing the hint would be more intrusive than the hint itself!

0

Please sign in to leave a comment.