How to create a diagnostic to mark the span as grey code?

Topics: APIs
Jun 7, 2014 at 11:41 PM
I'm trying to create a diagnostic that makes a certain span grayed out, like unused using directive or a redundant cast, but I cannot make it grayed out. I tried setting the DiagnosticSeverity to None, but that didn't really work...

I'm sure I'm missing something, any hint?
Jun 8, 2014 at 6:01 PM
I think it'll have to be a classifier. or tagger. But there are very few (if any) examples that use the roslyn code API and the Visual Studio SDK.

This one of the issues I have with the samples,
Coordinator
Jun 12, 2014 at 10:37 PM
Edited Jun 12, 2014 at 10:42 PM
This is supported, but we don't yet have any open-source diagnostics or sample diagnostics that demonstrate how this works.

If you're using the latest Visual Studio "14" CTP 1 SDK Preview bits, the way you do this is to set a severity of Hidden and a custom tag of Unnecessary. The IDE already has a tagger that looks for that well-known tag and displays it as a faded code region. This is the same way that the built-in "Unnecessary ..." diagnostics work.

This is currently the only well-known custom tag that we expect diagnostic authors to use out-of-the-box. You can also use the custom tag system as a handshake for your own custom VS code taggers, which you could then write yourself.

An example:
private static readonly DiagnosticDescriptor myRuleDescriptor = new DiagnosticDescriptor(
    MyId,
    MyDescription,
    MyFormat,
    MyCategory,
    DiagnosticSeverity.Hidden,
    isEnabledByDefault: true,
    customTags: WellKnownDiagnosticTags.Unnecessary);
Jun 12, 2014 at 10:45 PM
Thanks for the answers, Adam and Alex, I'm glad I don't have to implement my own tagger :)

So this is only in "14"? The "Unnecessary" tag is not supported in the 2013 preview?
Coordinator
Jun 12, 2014 at 11:47 PM
Edited Jun 13, 2014 at 6:10 PM
For BUILD Preview, we had an earlier design. I believe the approach when that branch snapped was that you would set the Severity to “None” and the Category to “Unnecessary”. If that doesn’t work for you, let me know and I’ll check into how things were working then.